﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using SIS.ENT;
using SIS.BLL;
using System.Globalization;
using SIS.Utilities;
using SIS.UI;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


public partial class Teacher_TeacherEntry : System.Web.UI.Page
{
    #region "Events"
    public Common _common = new Common();
    public int _UserAccountKey = -1;
    public int _SchoolKey = -1;
     

    protected void Page_Load(object sender, EventArgs e)
    {
        lblTopMessage.Text = DateTime.Now.ToString();
        if (!Page.IsPostBack)
        {
            SIS.Utilities.General.LoadDayDropdownList(ddlDOBDay);
            SIS.Utilities.General.LoadMonthDropdownList(ddlDOBMonth, 2);
            SIS.Utilities.General.LoadYearDropdownList(ddlDOBYear, (DateTime.Now.Year - 45), DateTime.Now.Year, 1);
            _common.LoadNationalityDDL(ddlNationality, string.Empty);
            _common.LoadTravelDocDDL(ddlTravelDocType, string.Empty);
            _common.LoadBloodGroupDDL(ddlBloodGroup, string.Empty);
            _common.LoadDrivingLicenseTypeDDL(ddlDrivingLicenceType, string.Empty);
            _common.LoadMartialStatusCodeDDL(ddlMaritalStatus, string.Empty);
            _common.LoadRaceCodeDDL(ddlRaceCode, string.Empty);
            _common.LoadReligionCodeDDL(ddlReligion, string.Empty);
            _common.LoadCurrencyCodeDDL(ddlCurrency, string.Empty);
            _common.LoadDesignationCodeDDL(ddlJobDesignation, string.Empty);
            _common.LoadPaymentTypeCodeCodeDDL(ddlpaymentType, string.Empty);
            _common.LoadParentStatusDDL(ddlParentStatus, string.Empty);

            _common.LoadCountryCodeDDL(ddlCountry, string.Empty);           
            _common.LoadCountryCodeDDL(ddlPCountry, string.Empty);

            ddlSchoolList.Text = System.Configuration.ConfigurationManager.AppSettings["SchoolKeyDefault"].ToString();

            if (Request.Params["id"] != null)
            {

                if (Int32.TryParse(Request.Params["id"].ToString(), out _UserAccountKey))
                {
                    
                    LoadTeacherInfo(_UserAccountKey);
                }
                else
                {
                    lblTopMessage.Text = "Invalid teacher account ID.";
                }

                lblTopMessage.Text = DateTime.Now.ToString();
            }
            else
            {
                tbpSubjects.Visible = false;
                tbpDesignation.Visible = false;
                tbpSalary.Visible = false;                
                tbpInfo3.Visible = false;
                tbpInfo4.Visible = false;
                tbpInfo5.Visible = false;
                lblSubjectCaption.Visible = false;
                lblExperienceHistory.Visible = false;
                lblHeaderQualification.Visible = false;
                lblOtherSkills.Visible = false;
                lblDesignation.Visible = false;
                lblSalary.Visible = false;        
            }
        }
        tbcEntry.ActiveTab = tbpInfo;
    }

    protected void btnAddNewTeacher_Click(object sender, EventArgs e)
    {
        Response.Redirect("TeacherEntry.aspx");
    }

    protected void btnViewTeacherList_Click(object sender, EventArgs e)
    {
        Response.Redirect("Teachers-List.aspx");
    }

    protected void ddlSchoolList_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void ddlDistrict_SelectedIndexChanged(object sender, EventArgs e)
    {
        _common.LoadCityCodeDDL(ddlCity, Convert.ToInt32(ddlDistrict.SelectedValue), Convert.ToInt16(ddlCountry.SelectedValue), string.Empty);
        tbcEntry.ActiveTab = tbpInfo2;
    }

    protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlCountry.SelectedIndex >= 0)
        {
            _common.LoadDistrictCodeDDL(ddlDistrict, Convert.ToInt16(ddlCountry.SelectedItem.Value), string.Empty);
        }

        if (ddlDistrict.SelectedIndex >= 0)
        {
            _common.LoadCityCodeDDL(ddlCity, Convert.ToInt32(ddlDistrict.SelectedValue), Convert.ToInt16(ddlCountry.SelectedValue), string.Empty);
        }

        //System.Web.UI.ScriptManager.GetCurrent(this).SetFocus(this.tbpInfo2);
        tbcEntry.ActiveTab = tbpInfo2;
    }

    protected void ddlPDistrict_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlPDistrict.SelectedIndex >= 0)
        {
            _common.LoadCityCodeDDL(ddlPCity, Convert.ToInt32(ddlPDistrict.SelectedValue), Convert.ToInt16(ddlPCountry.SelectedValue), string.Empty);
            tbcEntry.ActiveTab = tbpInfo2;
        }
    }

    protected void ddlPCountry_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlPCountry.SelectedIndex >= 0)
        {
            _common.LoadDistrictCodeDDL(ddlPDistrict, Convert.ToInt16(ddlPCountry.SelectedItem.Value), string.Empty);
        }

        if (ddlDistrict.SelectedIndex > 0)
        {
            _common.LoadCityCodeDDL(ddlPCity, Convert.ToInt32(ddlPDistrict.SelectedValue), Convert.ToInt16(ddlPCountry.SelectedValue), string.Empty);
        }

        //System.Web.UI.ScriptManager.GetCurrent(this).SetFocus(this.tbpInfo2);
        tbcEntry.ActiveTab = tbpInfo2;
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        lblMessage.Text = "";
        bool _status = true;
        Page.Validate("TeacherProfile");
        if (Page.IsValid)
        {
            UserAccountTable _account = new UserAccountTable();
            _account.UserAccountKey = Convert.ToInt32(lblUserAccountKey.Text);
            _account.SchoolKey = Convert.ToInt32(ddlSchoolList.Text);
            if (_account.UserAccountKey <= 0)
            {
                _account.UserAccountTypeCode = 200;
                _account.AuthCode = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 6);
                _account.AuthSalt = "TeacherGUID" + _account.AuthCode;

                _account.UserAccountAlternateKey = txtFirstName.Text.Replace(" ", ".") + txtLastName.Text.Replace(" ", ".") + "@" + ddlSchoolList.Text;
                lblUserAuthCode.Text = _account.UserAccountAlternateKey + " With " + _account.AuthCode + " salted " + _account.AuthSalt;
                _account.Status = -1;

                UserAccountTableManager.Save(_account).ToString();

                if (_account.UserAccountKey <= 0)
                {
                    lblMessage.Text = "Saving user account was failed!";
                    _status = false;
                    return;
                }
                else
                {
                    lblUserAccountKey.Text = _account.UserAccountKey.ToString();
                }
            }


            TeacherProfileTable _sprofile = new TeacherProfileTable();             
            TeacherContactTable _scontact = new TeacherContactTable();            
            TeacherAddressTable _sraddress = new TeacherAddressTable();
            TeacherAddressTable _spaddress = new TeacherAddressTable();


            _sprofile.UserAccountKey = _account.UserAccountKey;
            _scontact.UserAccountKey = _account.UserAccountKey;
            _sraddress.UserAccountKey = _account.UserAccountKey;
            _spaddress.UserAccountKey = _account.UserAccountKey;


            _sprofile.TeacherProfileKey = Convert.ToInt32(lblTeacherProfileKey.Text);
            _scontact.TeacherContactKey = Convert.ToInt32(lblTeacherContactKey.Text);
            _sraddress.TeacherAddressKey = Convert.ToInt32(lblTeacherRAddressKey.Text);
            _spaddress.TeacherAddressKey = Convert.ToInt32(lblTeacherPAddressKey.Text);

            _sprofile.FirstName = txtFirstName.Text;
            _sprofile.LastName = txtLastName.Text;
            _sprofile.OtherName = txtOtherName.Text;
            _sprofile.Gender = ddlGender.SelectedValue;

            DateTime _dtDOB = DateTime.Now;
            string _strDOB = string.Empty;
            _sprofile.DateOfBirth = new DateTime(1900, 1, 1);

            _strDOB = ddlDOBDay.Text + "/" + ddlDOBMonth.SelectedItem.Text + "/" + ddlDOBYear.Text.ToString();
            string StartDate = _strDOB;
            var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MMM-yyyy", DateSeparator = "-" };
            if (ddlDOBDay.SelectedValue == "-1" && ddlDOBMonth.SelectedValue == "-1" && ddlDOBYear.SelectedValue == "-1")
            {
                _sprofile.DateOfBirth = new DateTime(1900, 1, 1);
            }
            else
            {
                DateTime objStartDate = Convert.ToDateTime(_strDOB, dtfi1);
                if (SIS.Utilities.General.GetDateTime(_strDOB, out _dtDOB))
                {
                    _sprofile.DateOfBirth = objStartDate;
                }
                else
                {
                    //lblMessage.Text += _strDOB + " " + "NO User DOB: " + _dtDOB.ToString("dd/MMM/yyyy") + "<br/>";
                }
            }

            _sprofile.NRICNumber = txtNRICNumber.Text;

            _sprofile.DrivingLicenceType = Convert.ToInt16(ddlDrivingLicenceType.Text);
            _sprofile.DrivingLicenseNumber = txtDrivingLicenceNumber.Text;

            _sprofile.TravelDocumentType = Convert.ToInt16(ddlTravelDocType.Text);
            _sprofile.TravelDocumentNumber = txtTravelDocNumber.Text;

            _sprofile.BloodGroupCode = Convert.ToInt16(ddlBloodGroup.Text);
            _sprofile.MartialStatusCode = Convert.ToInt16(ddlMaritalStatus.Text);
            _sprofile.RaceCode = Convert.ToInt16(ddlRaceCode.Text);
            _sprofile.ReligionCode = Convert.ToInt16(ddlReligion.Text);
            _sprofile.NationalityCode = Convert.ToInt16(ddlNationality.Text);
            _sprofile.Hobby = txtHobby.Text;
            _sprofile.ParentStatus = Convert.ToInt16(ddlParentStatus.SelectedValue);
            _sprofile.PlaceOfBirth = txtPlaceOfBirth.Text;
            string SignInDate = ("01-01-1900") ;
            if (!txtJoinDate.Text.Equals(string.Empty))
            {
                 SignInDate = txtJoinDate.Text;                
            }           
            var dtInfo = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
            DateTime objSignInDate = Convert.ToDateTime(SignInDate, dtInfo);
            _sprofile.JoinDate = objSignInDate;
           
            _sprofile.Status = 1;
            _sprofile.WebSiteUrl = txtWebsiteUrl.Text;
            _sprofile.CreatedDateTime = DateTime.Now;
            _sprofile.ModifiedDateTime = DateTime.Now;       

            TeacherProfileTableManager.Save(_sprofile);
            if (_sprofile.TeacherProfileKey <= 0)
            {
                lblMessage.Text += "Saving profile was failed!<br/>";
                _status = false;               
            }
            else
            {
                lblTeacherProfileKey.Text = _sprofile.TeacherProfileKey.ToString();
                
            }

            //if (_sprofile.TeacherProfileKey > 0 && FormStatus == "OLD")             
            //{
                _scontact.EmailAddress = txtEmailAddress.Text;
                _scontact.MobileNumber = txtMobileNumber.Text;
                _scontact.HomePhoneNumber = txtHomePhoneNumber.Text;
                _scontact.OtherNumber = txtOtherContactNumber.Text;
                _scontact.OfficePhoneNumber = txtOfficeNumber.Text;
                _scontact.FaxNumber = txtFaxNumber.Text;
                _scontact.Status = 1;
                _scontact.CreatedDateTime = DateTime.Now;
                _scontact.ModifiedDateTime = DateTime.Now;
                TeacherContactTableManager.Save(_scontact);


                if (_scontact.TeacherContactKey <= 0)
                {
                    lblMessage.Text += "Saving contact was failed!<br/>";
                    _status = false;
                    //lblStudentContactKey.Text = "-1";
                }
                else
                {
                    lblTeacherContactKey.Text = _scontact.TeacherContactKey.ToString();
                }

                //Resident Address
                _sraddress.UnitNo = txtUnitNo.Text;
                _sraddress.StreetName = txtStreetName.Text;
                _sraddress.CountryCode = Convert.ToInt16(ddlCountry.Text);
                _sraddress.DistrictCode = Convert.ToInt16(ddlDistrict.Text);
                _sraddress.CityCode = Convert.ToInt16(ddlCity.Text);
                _sraddress.PostalCode = txtPostCode.Text;
                _sraddress.AddressTypeCode = 1;
                _sraddress.Status = 1;
                _sraddress.CreatedDateTime = DateTime.Now;
                _sraddress.ModifiedDateTime = DateTime.Now;
                TeacherAddressTableManager.Save(_sraddress);

                if (_sraddress.TeacherAddressKey <= 0)
                {
                    lblMessage.Text += "Saving Resident address was failed!<br/>";
                    _status = false;
                    //lblStudentAddressKey.Text = "-1";
                }
                else
                {
                    lblTeacherRAddressKey.Text = _sraddress.TeacherAddressKey.ToString();
                }

                //Permanent Address
                if (chkPSameAsResident.Checked)
                {
                    _spaddress.UnitNo = txtUnitNo.Text;
                    _spaddress.StreetName = txtStreetName.Text;
                    _spaddress.CountryCode = Convert.ToInt16(ddlCountry.Text);
                    _spaddress.DistrictCode = Convert.ToInt16(ddlDistrict.Text);
                    _spaddress.CityCode = Convert.ToInt16(ddlCity.Text);
                    _spaddress.PostalCode = txtPostCode.Text;
                    _spaddress.Status = 1;
                    _spaddress.CreatedDateTime = DateTime.Now;
                    _spaddress.ModifiedDateTime = DateTime.Now;
                }
                else
                {
                    _spaddress.UnitNo = txtPUnitNo.Text;
                    _spaddress.StreetName = txtPStreetName.Text;
                    _spaddress.CountryCode = Convert.ToInt16(ddlPCountry.Text);
                    _spaddress.DistrictCode = Convert.ToInt16(ddlPDistrict.Text);
                    _spaddress.CityCode = Convert.ToInt16(ddlPCity.Text);
                    _spaddress.PostalCode = txtPPostCode.Text;
                    _spaddress.Status = 1;
                    _spaddress.CreatedDateTime = DateTime.Now;
                    _spaddress.ModifiedDateTime = DateTime.Now;
                }

                _spaddress.AddressTypeCode = 2;

                TeacherAddressTableManager.Save(_spaddress);

                if (_spaddress.TeacherAddressKey <= 0)
                {
                    lblMessage.Text += "Saving Permanent address was failed!<br/>";
                    _status = false;
                    //lblStudentAddressKey.Text = "-1";
                }
                else
                {
                    lblTeacherPAddressKey.Text = _spaddress.TeacherAddressKey.ToString();
                }
                if (_sprofile.TeacherProfileKey > 0 && _account.UserAccountKey >0)
                {
                    tbpSubjects.Visible = true;
                    tbpDesignation.Visible = true;                    
                    tbpSalary.Visible = true;
                    tbpInfo3.Visible = true;
                    tbpInfo4.Visible = true;
                    tbpInfo5.Visible = true;
                    lblSubjectCaption.Visible = true;
                    lblExperienceHistory.Visible = true;
                    lblHeaderQualification.Visible = true;
                    lblOtherSkills.Visible = true;
                    lblDesignation.Visible = true;
                    lblSalary.Visible = true;
                }


            //}

            /////******************


            //int count = 0;
            ////Save Job Experience
            //DataTable lDT = new DataTable();
            //lDT = (DataTable)Session["JobExperiencesDT"];
            //foreach (DataRow lDR in lDT.Rows)
            //{
            //    TeacherJobExperiencesTable objTeacherJobExp = new TeacherJobExperiencesTable();
            //    if (Convert.ToString(lDR["Status"]) != "Delete")
            //    {
            //        if (Convert.ToString(lDR["Status"]) == "New")
            //        {
            //            objTeacherJobExp.TeacherJobExperienceKey = Convert.ToInt32(-1);
            //        }
            //        else
            //        {
            //            objTeacherJobExp.TeacherJobExperienceKey = (int)lDR["TeacherJobExperienceKey"];
            //        }

            //        objTeacherJobExp.UserAccountKey = _account.UserAccountKey;
            //        objTeacherJobExp.PartnerSchool = lDR["PartnerSchool"].ToString();
            //        objTeacherJobExp.StartDate = (DateTime)lDR["StartDate"];
            //        objTeacherJobExp.EndDate = (DateTime)lDR["EndDate"];
            //        objTeacherJobExp.LevelTaught = Convert.ToString(lDR["LevelTaught"]);
            //        objTeacherJobExp.BasicSalary = Convert.ToDecimal(lDR["BasicSalary"]);
            //        objTeacherJobExp.RefereeName = Convert.ToString(lDR["RefereeName"]);
            //        objTeacherJobExp.RefereeAddress = Convert.ToString(lDR["RefereeAddress"]);
            //        objTeacherJobExp.RefereeEmail = Convert.ToString(lDR["RefereeEmail"]);
            //        objTeacherJobExp.RefereeContact = Convert.ToString(lDR["RefereeContact"]);
            //        objTeacherJobExp.Remarks = Convert.ToString(lDR["Remarks"]);
            //        objTeacherJobExp.Status = 1;
            //        objTeacherJobExp.CreatedDateTime = DateTime.Now;
            //        objTeacherJobExp.ModifiedDateTime = DateTime.Now;

            //        TeacherJobExperiencesTableManager.Save(objTeacherJobExp);
            //        if (objTeacherJobExp.TeacherJobExperienceKey <= 0)
            //        {
            //            lblMessage.Text += "Saving Job Experiences was failed!<br/>";
            //            _status = false;
            //        }
            //        else
            //        {
            //            count++;
            //        }
            //    }
            //    else
            //    {
            //        bool lresult = TeacherJobExperiencesTableManager.Delete((int)lDR["TeacherJobExperienceKey"]);
            //    }
            //}
            //if (count > 0)
            //{
            //    lblTeacherJobExperienceKey.Text = "Saved Successfully.Total Record" + count.ToString();
            //}


            //count = 0;
            ////Save Teacher Designation
            //DataTable lDesignationDT = new DataTable();
            //lDesignationDT = (DataTable)Session["TeacherDesignationsDT"];
            //foreach (DataRow lDR in lDesignationDT.Rows)
            //{
            //    TeacherDesignationTable objTeacherDesignation = new TeacherDesignationTable();
            //    if (Convert.ToString(lDR["Status"]) != "Delete")
            //    {
            //        if (Convert.ToString(lDR["Status"]) == "New")
            //        {
            //            objTeacherDesignation.TeacherDesignationKey = Convert.ToInt32(-1);//(int)lDR["TeacherDesignationKey"];
            //        }
            //        else
            //        {
            //            objTeacherDesignation.TeacherDesignationKey = (int)lDR["TeacherDesignationKey"];
            //        }

            //        objTeacherDesignation.UserAccountKey = _account.UserAccountKey;
            //        objTeacherDesignation.JobDesignationCode = (Int16)lDR["JobDesignationCode"];
            //        objTeacherDesignation.StartDate = (DateTime)lDR["StartDate"];
            //        objTeacherDesignation.EndDate = (DateTime)lDR["EndDate"];
            //        objTeacherDesignation.JobDescriptionDetail = Convert.ToString(lDR["JobDescriptionDetail"]);
            //        objTeacherDesignation.Active = (Boolean)(lDR["Active"]);
            //        objTeacherDesignation.Remarks = Convert.ToString(lDR["Remarks"]);
            //        objTeacherDesignation.Status = 1;
            //        objTeacherDesignation.CreatedDateTime = DateTime.Now;
            //        objTeacherDesignation.ModifiedDateTime = DateTime.Now;

            //        TeacherDesignationTableManager.Save(objTeacherDesignation);
            //        if (objTeacherDesignation.TeacherDesignationKey <= 0)
            //        {
            //            lblMessage.Text += "Saving Teacher Designation was failed!<br/>";
            //            _status = false;
            //        }
            //        else
            //        {
            //            count++;
            //        }
            //    }
            //    else
            //    {
            //        bool lResult = TeacherDesignationTableManager.Delete((int)lDR["TeacherDesignationKey"]);
            //    }
            //}
            //if (count > 0)
            //{
            //    lblJobDesignationKey.Text = "Saved Successfully.";
            //}


            //count = 0;
            ////Save Salary
            //DataTable lSalaryDT = new DataTable();
            //lSalaryDT = (DataTable)Session["TeacherSalaryDT"];
            //foreach (DataRow lDR in lSalaryDT.Rows)
            //{
            //    TeacherSalaryTable objTeacherSalary = new TeacherSalaryTable();
            //    if (Convert.ToString(lDR["Status"]) != "Delete")
            //    {
            //        if (Convert.ToString(lDR["Status"]) == "New")
            //        {
            //            objTeacherSalary.TeacherSalaryKey = Convert.ToInt32(-1);
            //        }
            //        else
            //        {
            //            objTeacherSalary.TeacherSalaryKey = (int)lDR["TeacherSalaryKey"];
            //        }

            //        objTeacherSalary.UserAccountKey = _account.UserAccountKey;
            //        objTeacherSalary.PaymentTypeCode = (Int16)lDR["PaymentTypeCode"];
            //        objTeacherSalary.StartDate = (DateTime)lDR["StartDate"];
            //        objTeacherSalary.EndDate = (DateTime)lDR["EndDate"];
            //        objTeacherSalary.CurrencyCode = (Int16)lDR["CurrencyCode"];
            //        objTeacherSalary.Amount = Convert.ToDecimal(lDR["Amount"]);
            //        objTeacherSalary.Allotment1 = Convert.ToDecimal(lDR["Allotment1"]);
            //        objTeacherSalary.Allotment2 = Convert.ToDecimal(lDR["Allotment2"]);
            //        objTeacherSalary.Active = (Boolean)(lDR["Active"]);
            //        objTeacherSalary.Remarks = Convert.ToString(lDR["Remarks"]);
            //        objTeacherSalary.Status = 1;
            //        objTeacherSalary.CreatedDateTime = DateTime.Now;
            //        objTeacherSalary.ModifiedDateTime = DateTime.Now;

            //        TeacherSalaryTableManager.Save(objTeacherSalary);
            //        if (objTeacherSalary.TeacherSalaryKey <= 0)
            //        {
            //            lblMessage.Text += "Saving Teacher Salary was failed!<br/>";
            //            _status = false;
            //        }
            //        else
            //        {
            //            count++;
            //        }
            //    }
            //    else
            //    {
            //        bool lResult = TeacherSalaryTableManager.Delete((int)lDR["TeacherSalaryKey"]);
            //    }
            //}
            //if (count > 0)
            //{
            //    lblSalaryKey.Text = "Saved Successfully.Total Record" + count.ToString();
            //}

            //QualificationDT

        //    count = 0;
        //    //Save qUALIFICATION
        //    DataTable lQualificationDT = new DataTable();
        //    lQualificationDT = (DataTable)Session["QualificationDT"];
        //    foreach (DataRow lDR in lQualificationDT.Rows)
        //    {
        //        TeacherQualtificationTable objTeacherQualify = new TeacherQualtificationTable();
        //        if (Convert.ToString(lDR["Status"]) != "Delete")
        //        {
        //            if (Convert.ToString(lDR["Status"]) == "New")
        //            {
        //                objTeacherQualify.TeacherQualtificationKey = Convert.ToInt32(-1);//(int)lDR["TeacherDesignationKey"];
        //            }
        //            else
        //            {
        //                objTeacherQualify.TeacherQualtificationKey = (int)lDR["TeacherQualtificationKey"];
        //            }

        //            objTeacherQualify.UserAccountKey = _account.UserAccountKey;
        //            objTeacherQualify.QualificationName = Convert.ToString(lDR["QualificationName"]);
        //            objTeacherQualify.Organization = Convert.ToString(lDR["Organization"]);
        //            objTeacherQualify.GradeLevel = Convert.ToString(lDR["GradeLevel"]);
        //            objTeacherQualify.Year = Convert.ToString(lDR["Year"]);
        //            objTeacherQualify.Others = Convert.ToString(lDR["Others"]);
        //            objTeacherQualify.Status = 1;
        //            objTeacherQualify.CreatedDateTime = DateTime.Now;
        //            objTeacherQualify.ModifiedDateTime = DateTime.Now;

        //            TeacherQualtificationTableManager.Save(objTeacherQualify);
        //            if (objTeacherQualify.TeacherQualtificationKey <= 0)
        //            {
        //                lblMessage.Text += "Saving Teacher Qualification was failed!<br/>";
        //                _status = false;
        //            }
        //            else
        //            {
        //                count++;
        //            }
        //        }
        //        else
        //        {
        //            bool lResult = TeacherQualtificationTableManager.Delete((int)lDR["TeacherQualtificationKey"]);
        //        }
        //    }
        //    if (count > 0)
        //    {
        //        lblQualificationKey.Text = "Saved Successfully. ";
        //    }

        //    //TeacherOtherSkillsDT
        //    DataTable lSkillDT = new DataTable();
        //    lSkillDT = (DataTable)Session["TeacherOtherSkillsDT"];
        //    foreach (DataRow lDR in lSkillDT.Rows)
        //    {
        //        TeacherOtherSkillsTable objTeacherSkill = new TeacherOtherSkillsTable();
        //        if (Convert.ToString(lDR["Status"]) != "Delete")
        //        {
        //            if (Convert.ToString(lDR["Status"]) == "New")
        //            {
        //                objTeacherSkill.TeacherOtherSkillsKey = Convert.ToInt32(-1);
        //            }
        //            else
        //            {
        //                objTeacherSkill.TeacherOtherSkillsKey = (int)lDR["TeacherOtherSkillsKey"];
        //            }

        //            objTeacherSkill.UserAccountKey = _account.UserAccountKey;
        //            objTeacherSkill.SkillName = Convert.ToString(lDR["SkillName"]);
        //            objTeacherSkill.Organization = Convert.ToString(lDR["Organization"]);
        //            objTeacherSkill.SkillLevel = Convert.ToString(lDR["SkillLevel"]);
        //            objTeacherSkill.NoOfYear = Convert.ToString(lDR["NoOfYear"]);
        //            objTeacherSkill.Others = Convert.ToString(lDR["Others"]);
        //            objTeacherSkill.Status = 1;
        //            objTeacherSkill.CreatedDateTime = DateTime.Now;
        //            objTeacherSkill.ModifiedDateTime = DateTime.Now;

        //            TeacherOtherSkillsTableManager.Save(objTeacherSkill);
        //            if (objTeacherSkill.TeacherOtherSkillsKey <= 0)
        //            {
        //                lblMessage.Text += "Saving Teacher Skill was failed!<br/>";
        //                _status = false;
        //            }
        //            else
        //            {
        //                count++;
        //            }
        //        }
        //        else
        //        {
        //            bool lresult = TeacherOtherSkillsTableManager.Delete((int)lDR["TeacherOtherSkillsKey"]);
        //        }

        //    }
        //    if (count > 0)
        //    {
        //        lblSkillKey.Text = "Saved Successfully. ";
        //    }

        //    if (lblMessage.Text.Length == 0)
        //    {
        //        lblTopMessage.Text = "Saving was succeeded at " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm tt");
        //        lblMessage.Text = "Saving was succeeded at " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm tt");
        //    }

        //    if (lblTeacherProfileKey.Text != "-1")
        //    {
        //        btnUpdatePhoto.Visible = true;
        //    }
        //    else
        //    {
        //        btnUpdatePhoto.Visible = false;
        //    }
        }
    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (txtPartnerSchool.Text.Equals(String.Empty))
        {
            lblMessage.Text = "Partner School,Start Date,End Date should not blank.";

        }
        else
        {
            if (txtStartDate.Text.Equals(String.Empty) || txtEndDate.Text.Equals(String.Empty))
            {

                lblMessage.Text = "Start Date,End Date should not blank.";
            }
        }
        if (!txtPartnerSchool.Text.Equals(String.Empty) && !(txtStartDate.Text.Equals(String.Empty) && txtEndDate.Text.Equals(String.Empty)))
        {
            Page.Validate("JobExperience");
            if (Page.IsValid)
            {

                Int32 JobExpeienceKey = 0;
                 if (btnAdd.Text == "Add New")
                 {
                     JobExpeienceKey=Convert.ToInt32(-1);
                     AddTeacherExperience(JobExpeienceKey, txtPartnerSchool.Text, txtStartDate.Text, txtEndDate.Text, txtLevelTaught.Text, txtSalary.Text, txtRefereeName.Text, txtRefereeAddress.Text, txtRefereeEmail.Text, txtRefereeContact.Text, txtRemarks.Text);
                     //AddToTempTable(txtPartnerSchool.Text, txtStartDate.Text, txtEndDate.Text, txtLevelTaught.Text, txtSalary.Text, txtRefereeName.Text, txtRefereeAddress.Text, txtRefereeEmail.Text, txtRefereeContact.Text, txtRemarks.Text);
                 }
                else
                {
                     
                    JobExpeienceKey = Convert.ToInt32(lblJobExperienceKey.Text);
                    AddTeacherExperience(JobExpeienceKey, txtPartnerSchool.Text, txtStartDate.Text, txtEndDate.Text, txtLevelTaught.Text, txtSalary.Text, txtRefereeName.Text, txtRefereeAddress.Text, txtRefereeEmail.Text, txtRefereeContact.Text, txtRemarks.Text);
                    btnAdd.Text = "Add New"; //reset
                    lblJobExperienceKey.Text = "-1"; //reset
                    //UpdateTempTable(lblJobExperienceKey.Text, lblAccountKey.Text, txtPartnerSchool.Text, txtStartDate.Text, txtEndDate.Text, txtLevelTaught.Text, Convert.ToDecimal(txtSalary.Text), txtRefereeName.Text, txtRefereeAddress.Text, txtRefereeEmail.Text, txtRefereeContact.Text, txtRemarks.Text);
                }
            }
        }
        tbcEntry.ActiveTab = tbpInfo3;

    }

    private void AddTeacherExperience(int TeacherJobExperienceKey ,string PartnerSchool, string dStartDate, string dEndDate, string LevelTaught, string BasicSalary, string RefereeName, string RefereeAddress, string RefereeEmail, string RefereeContact, string Remarks)
    {

        TeacherJobExperiencesTable objTeacherJobExp = new TeacherJobExperiencesTable();
        UserAccountTable _account = new UserAccountTable();
        _account.UserAccountKey = Convert.ToInt32(lblUserAccountKey.Text);
        objTeacherJobExp.UserAccountKey = _account.UserAccountKey;
        string StartDate = dStartDate;
        var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
        DateTime objStartDate = Convert.ToDateTime(StartDate, dtfi1);
        
        string EndDate = dEndDate;
        var dtfi2 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
        DateTime objEndDate = Convert.ToDateTime(EndDate, dtfi2);

        objTeacherJobExp.TeacherJobExperienceKey = TeacherJobExperienceKey;
        objTeacherJobExp.PartnerSchool = PartnerSchool;
        objTeacherJobExp.StartDate = objStartDate;
        objTeacherJobExp.EndDate = objEndDate;
        objTeacherJobExp.LevelTaught = LevelTaught;
        objTeacherJobExp.BasicSalary = Convert.ToDecimal(BasicSalary);
        objTeacherJobExp.RefereeName = Convert.ToString(RefereeName);
        objTeacherJobExp.RefereeAddress = Convert.ToString(RefereeAddress);
        objTeacherJobExp.RefereeEmail = Convert.ToString( RefereeEmail);
        objTeacherJobExp.RefereeContact = Convert.ToString(RefereeContact);
        objTeacherJobExp.Remarks = Convert.ToString( Remarks);
        objTeacherJobExp.Status = 1;
        objTeacherJobExp.CreatedDateTime = DateTime.Now;
        objTeacherJobExp.ModifiedDateTime = DateTime.Now;

        TeacherJobExperiencesTableManager.Save(objTeacherJobExp);
        if (objTeacherJobExp.TeacherJobExperienceKey <= 0)
        {
            lblMessage.Text += "Saving Job Experiences was failed!<br/>";
        }
        else
        {
            ClearJobExperienceRecord();
            FillTeacherJobExperience(_account.UserAccountKey);
        }
        
    }       

    protected void btnQualifyAdd_Click(object sender, EventArgs e)
    {
        if (txtQualification2.Text.Equals(String.Empty))
        {
            lblMessage.Text = "Qualification should not blank.";

        }
        else
        {

            //Page.Validate("TeacherProfile");
            //if (Page.IsValid)
            //{
            Int32 QualificationKey = 0;
                if (btnQualifyAdd.Text == "Add New")
                {
                    QualificationKey = Convert.ToInt32(-1);
                    AddQualification(QualificationKey, txtQualification2.Text, txtOrganization.Text, txtYear.Text, txtGradelevel.Text, txtQualifyOthers.Text);
                    //AddToQualifyTempTable(txtQualification2.Text, txtOrganization.Text, txtYear.Text, txtGradelevel.Text, txtQualifyOthers.Text);
                }
                else
                {
                    QualificationKey = Convert.ToInt32(lblQualificationKey.Text);
                    AddQualification(QualificationKey, txtQualification2.Text, txtOrganization.Text, txtYear.Text, txtGradelevel.Text, txtQualifyOthers.Text);
                    btnQualifyAdd.Text = "Add New"; //reset
                    lblQualificationKey.Text = "-1"; //reset
                    //UpdateQualificationTempTable(lblQualificationKey.Text, txtQualification2.Text, txtOrganization.Text, txtYear.Text, txtGradelevel.Text, txtQualifyOthers.Text);
                }
            //}
        }
        tbcEntry.ActiveTab = tbpInfo4;

    }

    private void AddQualification(int TeacherQualtifiKey, string QualificationName, string Organization, string Year, string GradeLevel, string Others)
    {

        TeacherQualtificationTable objTeacherQualification = new TeacherQualtificationTable();
        UserAccountTable _account = new UserAccountTable();
        _account.UserAccountKey = Convert.ToInt32(lblUserAccountKey.Text);
        objTeacherQualification.UserAccountKey = _account.UserAccountKey;


        objTeacherQualification.TeacherQualtificationKey = TeacherQualtifiKey;
        objTeacherQualification.QualificationName = QualificationName;
        objTeacherQualification.Organization = Organization;
        objTeacherQualification.Year = Year;
        objTeacherQualification.GradeLevel = GradeLevel;
        objTeacherQualification.Others = Others;        
        objTeacherQualification.Status = 1;
        objTeacherQualification.CreatedDateTime = DateTime.Now;
        objTeacherQualification.ModifiedDateTime = DateTime.Now;

        TeacherQualtificationTableManager.Save(objTeacherQualification);
        if (objTeacherQualification.TeacherQualtificationKey <= 0)
        {
            lblMessage.Text += "Saving Teacher Qualification was failed!<br/>";
        }
        else
        {
            ClearQualificationRecord();
            FillTeacherQualification(_account.UserAccountKey);
        }

    }

    protected void btnSkillAdd_Click(object sender, EventArgs e)
    {
        if (txtSkill.Text.Equals(String.Empty))
        {
            lblMessage.Text = "Skill may not blank";

        }
        else
        {

            //Page.Validate("TeacherProfile");
            //if (Page.IsValid)
            //{
                Int32 OtherSkillKey = 0;

                if (btnSkillAdd.Text == "Add New")
                {
                    OtherSkillKey = Convert.ToInt32(-1);
                    AddOtherSkills(OtherSkillKey, txtSkill.Text, txtSkillOrganization.Text, txtNoOfYear.Text, txtSkillLevel.Text, txtSkillOthers.Text);
                    //AddToSkillTempTable(txtSkill.Text, txtSkillOrganization.Text, txtNoOfYear.Text, txtSkillLevel.Text, txtSkillOthers.Text);
                }
                else
                {
                    OtherSkillKey = Convert.ToInt32(lblSkillKey.Text);
                    AddOtherSkills(OtherSkillKey, txtSkill.Text, txtSkillOrganization.Text, txtNoOfYear.Text, txtSkillLevel.Text, txtSkillOthers.Text);
                    btnSkillAdd.Text = "Add New"; //reset
                    lblSkillKey.Text = "-1"; //reset
                    //UpdateSkillTempTable(lblSkillKey.Text, txtSkill.Text, txtSkillOrganization.Text, txtNoOfYear.Text, txtSkillLevel.Text, txtSkillOthers.Text);
                }
            //}
        }
        tbcEntry.ActiveTab = tbpInfo5;

    }

    private void AddOtherSkills(int TeacherOtherSkillKey, string SkillName, string Organization, string NoOfYear, string SkillLevel, string Others)
    {

        TeacherOtherSkillsTable objTeacherOtherSkill = new TeacherOtherSkillsTable();
        UserAccountTable _account = new UserAccountTable();
        _account.UserAccountKey = Convert.ToInt32(lblUserAccountKey.Text);
        objTeacherOtherSkill.UserAccountKey = _account.UserAccountKey;


        objTeacherOtherSkill.TeacherOtherSkillsKey = TeacherOtherSkillKey;
        objTeacherOtherSkill.SkillName = SkillName;
        objTeacherOtherSkill.SkillLevel = SkillLevel;
        objTeacherOtherSkill.Organization = Organization;
        objTeacherOtherSkill.NoOfYear = NoOfYear;
        objTeacherOtherSkill.Others = Others;
        objTeacherOtherSkill.Status = 1;
        objTeacherOtherSkill.CreatedDateTime = DateTime.Now;
        objTeacherOtherSkill.ModifiedDateTime = DateTime.Now;

        TeacherOtherSkillsTableManager.Save(objTeacherOtherSkill);
        if (objTeacherOtherSkill.TeacherOtherSkillsKey <= 0)
        {
            lblMessage.Text += "Saving Teacher Other Skill was failed!<br/>";
        }
        else
        {
            ClearOtherSkillRecord();
            FillTeacherOtherSkill(_account.UserAccountKey);
        }

    }

    protected void btnDesignationAdd_Click(object sender, EventArgs e)
    {
        if (txtDesignationDesc.Text.Equals(String.Empty))
        {
            lblMessage.Text = "Designation should not blank.";

        }

        else
        {
            if (txtDesgnationStartDate.Text.Equals(String.Empty) || txtDesgnationEndDate.Text.Equals(String.Empty))
            {

                lblMessage.Text = "Start Date,End Date should not blank.";
            }
        }
        if (!txtDesignationDesc.Text.Equals(String.Empty) && !(txtDesgnationStartDate.Text.Equals(String.Empty) && txtDesgnationEndDate.Text.Equals(String.Empty)))
        {

            Page.Validate("vgDesignation");
            if (Page.IsValid)
            {
                bool Active = true;
                int JobDesignationKey = 0; 
                if (chkDesignation.Checked == false)
                {
                    Active = false;
                }
                if (btnDesignationAdd.Text == "Add New")
                {
                    JobDesignationKey = Convert.ToInt32(-1);
                    AddDesignation(JobDesignationKey,Convert.ToInt16(ddlJobDesignation.SelectedValue), txtDesignationDesc.Text, txtDesgnationStartDate.Text, txtDesgnationEndDate.Text, txtDesignationRemark.Text, Active);
                    //AddToDesignationTempTable(Convert.ToInt16(ddlJobDesignation.SelectedValue), txtDesignationDesc.Text, txtDesgnationStartDate.Text, txtDesgnationEndDate.Text, txtDesignationRemark.Text, Active);
                }
                else
                {
                    JobDesignationKey = Convert.ToInt32(lblJobDesignationKey.Text);
                    AddDesignation(JobDesignationKey, Convert.ToInt16(ddlJobDesignation.SelectedValue), txtDesignationDesc.Text, txtDesgnationStartDate.Text, txtDesgnationEndDate.Text, txtDesignationRemark.Text, Active);
                    btnDesignationAdd.Text = "Add New"; //reset
                    lblJobDesignationKey.Text = "-1"; //reset
                    //UpdateDesignationTempTable(lblJobDesignationKey.Text, Convert.ToInt16(ddlJobDesignation.SelectedValue), txtDesignationDesc.Text, txtDesgnationStartDate.Text, txtDesgnationEndDate.Text, txtDesignationRemark.Text, Active);
                }
            }
        }
        tbcEntry.ActiveTab = tbpDesignation;

    }

    private void AddDesignation(int JobDesignationKey, Int16 JobDesignationCode, string JobDescriptionDetail, string dStartDate, string dEndDate, string Remark, bool Active)
    {

        TeacherDesignationTable objTeacherJobDesignation = new TeacherDesignationTable();
        UserAccountTable _account = new UserAccountTable();
        _account.UserAccountKey = Convert.ToInt32(lblUserAccountKey.Text);
        objTeacherJobDesignation.UserAccountKey = _account.UserAccountKey;
        string StartDate = dStartDate;
        var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
        DateTime objStartDate = Convert.ToDateTime(StartDate, dtfi1);
         
        string EndDate = dEndDate;
        var dtfi2 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
        DateTime objEndDate = Convert.ToDateTime(EndDate, dtfi2);
        objTeacherJobDesignation.TeacherDesignationKey = JobDesignationKey;
        objTeacherJobDesignation.JobDesignationCode = JobDesignationCode;
        objTeacherJobDesignation.JobDescriptionDetail = JobDescriptionDetail;
        objTeacherJobDesignation.StartDate = objStartDate;
        objTeacherJobDesignation.EndDate = objEndDate;
        objTeacherJobDesignation.Active = Active;
        objTeacherJobDesignation.Remarks = Remark;
        objTeacherJobDesignation.Status = 1;
        objTeacherJobDesignation.CreatedDateTime = DateTime.Now;
        objTeacherJobDesignation.ModifiedDateTime = DateTime.Now;

        TeacherDesignationTableManager.Save(objTeacherJobDesignation);
        if (objTeacherJobDesignation.TeacherDesignationKey <= 0)
        {
            lblMessage.Text += "Saving Teacher Job Designation was failed!<br/>";
        }
        else
        {
            ClearDesignationRecord();
            FillTeacherDesignation(_account.UserAccountKey);
        }

    }

    protected void btnSalaryAdd_Click(object sender, EventArgs e)
    {
        if (txtAmount.Text.Equals(String.Empty))
        {
            lblMessage.Text = "Amount should not blank.";
        }

        else
        {
            if (txtSalaryStartDate.Text.Equals(String.Empty) || txtSalaryEndDate.Text.Equals(String.Empty))
            {

                lblMessage.Text = "Start Date,End Date should not blank.";
            }
        }
        if (!txtAmount.Text.Equals(String.Empty) && !(txtSalaryStartDate.Text.Equals(String.Empty) && txtSalaryEndDate.Text.Equals(String.Empty)))
        {

            Page.Validate("vgSalary");
            if (Page.IsValid)
            {

                bool Active = true;
                int TeacherSalaryKey = 0;
                if (chkActive.Checked == false)
                {
                    Active = false;
                }
                if (btnSalaryAdd.Text == "Add New")
                {
                    TeacherSalaryKey = Convert.ToInt32(-1);
                    AddSalary(TeacherSalaryKey,Convert.ToInt16(ddlpaymentType.SelectedValue), Convert.ToInt16(ddlCurrency.SelectedValue), txtSalaryStartDate.Text, txtSalaryEndDate.Text, txtAmount.Text, txtAllotment1.Text, txtAllotment2.Text, txtSalaryRemark.Text, Active);
                    //AddToSalaryTempTable(Convert.ToInt16(ddlpaymentType.SelectedValue), Convert.ToInt16(ddlCurrency.SelectedValue), txtSalaryStartDate.Text, txtSalaryEndDate.Text, txtAmount.Text, txtAllotment1.Text, txtAllotment2.Text, txtSalaryRemark.Text, Active);
                }
                else
                {
                    TeacherSalaryKey = Convert.ToInt32(lblSalaryKey.Text);
                    AddSalary(TeacherSalaryKey, Convert.ToInt16(ddlpaymentType.SelectedValue), Convert.ToInt16(ddlCurrency.SelectedValue), txtSalaryStartDate.Text, txtSalaryEndDate.Text, txtAmount.Text, txtAllotment1.Text, txtAllotment2.Text, txtSalaryRemark.Text, Active);
                    btnSalaryAdd.Text = "Add New"; //reset
                    lblSalaryKey.Text = "-1"; //reset
                    //UpdateSalaryTempTable(lblSalaryKey.Text, Convert.ToInt16(ddlpaymentType.SelectedValue), Convert.ToInt16(ddlCurrency.SelectedValue), txtAmount.Text, txtAllotment1.Text, txtAllotment2.Text, txtSalaryStartDate.Text, txtSalaryEndDate.Text, txtSalaryRemark.Text, Active);
                }
            }
        }
        tbcEntry.ActiveTab = tbpSalary;

    }

    private void AddSalary(int TeacherSalaryKey, Int16 PaymentTypeCode, Int16 CurrencyCode, string dStartDate, string dEndDate, string Amount, string Allotment1, string Allotment2, string Remark, bool Active)
    {

        TeacherSalaryTable objTeacherSalary = new TeacherSalaryTable();
        UserAccountTable _account = new UserAccountTable();
        _account.UserAccountKey = Convert.ToInt32(lblUserAccountKey.Text);
        objTeacherSalary.UserAccountKey = _account.UserAccountKey;
        string StartDate = dStartDate;
        var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
        DateTime objStartDate = Convert.ToDateTime(StartDate, dtfi1);

        string EndDate = dEndDate;
        var dtfi2 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
        DateTime objEndDate = Convert.ToDateTime(EndDate, dtfi2);
        objTeacherSalary.TeacherSalaryKey = TeacherSalaryKey;
        objTeacherSalary.CurrencyCode = CurrencyCode;
        objTeacherSalary.PaymentTypeCode = PaymentTypeCode;
        objTeacherSalary.StartDate = objStartDate;
        objTeacherSalary.EndDate = objEndDate;
        objTeacherSalary.Amount = Convert.ToDecimal(Amount);
        objTeacherSalary.Allotment1 =  Allotment1.Equals(String.Empty) ? Convert.ToDecimal(0) : Convert.ToDecimal(Allotment1); //Convert.ToDecimal(Allotment1);
        objTeacherSalary.Allotment2 = Allotment2.Equals(String.Empty) ? Convert.ToDecimal(0) : Convert.ToDecimal(Allotment2); //Convert.ToDecimal(Allotment2);
        objTeacherSalary.Active = Active;
        objTeacherSalary.Remarks = Remark;
        objTeacherSalary.Status = 1;
        objTeacherSalary.CreatedDateTime = DateTime.Now;
        objTeacherSalary.ModifiedDateTime = DateTime.Now;

        TeacherSalaryTableManager.Save(objTeacherSalary);
        if (objTeacherSalary.TeacherSalaryKey <= 0)
        {
            lblMessage.Text += "Saving Teacher Salary was failed!<br/>";
        }
        else
        {
            ClearSalaryRecord();
            FillTeacherSalary(_account.UserAccountKey);
        }

    }

    protected void chkPSameAsResident_CheckedChanged(object sender, EventArgs e)
    {
        divPUnitNo.Visible = !chkPSameAsResident.Checked;
        divPStreetName.Visible = !chkPSameAsResident.Checked;
        divPCountry.Visible = !chkPSameAsResident.Checked;
        divPCity.Visible = !chkPSameAsResident.Checked;

        rfvPUnitNo.Enabled = !chkPSameAsResident.Checked;
        rfvPStreetName.Enabled = !chkPSameAsResident.Checked;
        rfvPCountry.Enabled = !chkPSameAsResident.Checked;
        rfvPDistrict.Enabled = !chkPSameAsResident.Checked;
        rfvPCity.Enabled = !chkPSameAsResident.Checked;
        rfvPPostCode.Enabled = !chkPSameAsResident.Checked;

        if (chkPSameAsResident.Checked)
        {
            chkPSameAsResident.ForeColor = System.Drawing.Color.Red;
        }
        else
        {
            chkPSameAsResident.ForeColor = System.Drawing.Color.Green;
        }
    }

    protected void btnBack_Click(object sender, EventArgs e)
    {

        Response.Redirect("Teachers-List.aspx");
    }    

    protected void dgExperienceBrowse_RowEditing(object sender, GridViewEditEventArgs e)
    {
        dgExperienceBrowse.EditIndex = e.NewEditIndex;
        DataTable lDT = new DataTable();
        TeacherJobExperiencesTableList _sJobExperiencesList = new TeacherJobExperiencesTableList();
        if (Request.Params["UserAccountKey"] != null != null)
        {
            _UserAccountKey = Convert.ToInt32(Request.Params["UserAccountKey"]);
        }
        Int32 ProfileKey = _UserAccountKey;
        _sJobExperiencesList = TeacherJobExperiencesTableManager.GetList(_UserAccountKey);
        //CreateTable(_sJobExperiencesList);
        dgExperienceBrowse.DataSource = _sJobExperiencesList;//Session["JobExperiencesDT"];
        dgExperienceBrowse.DataBind();
        lblTopMessage.Text = DateTime.Now.ToString();
        tbcEntry.ActiveTab = tbpInfo3;
    }

    protected void dgExperienceBrowse_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        dgExperienceBrowse.PageIndex = e.NewPageIndex;
        LoadTeacherInfo(_UserAccountKey);
    }

    protected void dgExperienceBrowse_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

        int TeacherJobExperienceKey = Convert.ToInt32(dgExperienceBrowse.DataKeys[e.RowIndex].Value);
        int UserAccountKey = Convert.ToInt32(lblUserAccountKey.Text);
        
        if (TeacherJobExperiencesTableManager.Delete(TeacherJobExperienceKey))
        {
            lblMessage.Text = "Teacher Job Experience deleted";
        }
        else
        {
            lblMessage.Text = "Teacher Job Experience Deleted Fail";
        }
        TeacherJobExperiencesTableList _TeacherQualificationList = TeacherJobExperiencesTableManager.GetList(UserAccountKey);
        //DataTable lDT = new DataTable();
        //lDT = (DataTable)Session["JobExperiencesDT"];
        //foreach (DataRow lDR in lDT.Rows)
        //{
        //    if (TeacherJobExperienceKey == Convert.ToInt32(lDR["TeacherJobExperienceKey"]))
        //    {
        //        lDR["Status"] = "Delete";
        //    }
        //}
        //lDT.AcceptChanges();
        dgExperienceBrowse.EditIndex = -1;
        dgExperienceBrowse.DataSource = _TeacherQualificationList;
        dgExperienceBrowse.DataBind();

    }

    protected void dgExperienceBrowse_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Page.Validate();
        if (Page.IsValid)
        {
            int TeacherJobExperienceKey = Convert.ToInt32(dgExperienceBrowse.DataKeys[e.RowIndex].Value);
            //int UserAccountKey = Convert.ToInt32(dgExperienceBrowse.Rows[e.RowIndex].Cells[1].Text);
            TextBox txtPartnerSchool = (TextBox)dgExperienceBrowse.Rows[e.RowIndex].FindControl("txtPartnerSchool1");
            TextBox txtStartDate = (TextBox)dgExperienceBrowse.Rows[e.RowIndex].FindControl("txtStartDate1");
            var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
            DateTime objStartDate = Convert.ToDateTime(txtStartDate.Text, dtfi1);
            TextBox txtEndDate = (TextBox)dgExperienceBrowse.Rows[e.RowIndex].FindControl("txtEndDate1");
            var dtfi2 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
            DateTime objEndDate = Convert.ToDateTime(txtEndDate.Text, dtfi1);
            TextBox txtLevelTaught = (TextBox)dgExperienceBrowse.Rows[e.RowIndex].FindControl("txtLevelTaught1");
            TextBox txtBasicSalary = (TextBox)dgExperienceBrowse.Rows[e.RowIndex].FindControl("txtBasicSalary1");
            TextBox txtDescription = (TextBox)dgExperienceBrowse.Rows[e.RowIndex].FindControl("txtDescription1");
            DataTable lDT = new DataTable();
            lDT = (DataTable)Session["JobExperiencesDT"];
            foreach (DataRow lDR in lDT.Rows)
            {
                if (TeacherJobExperienceKey == Convert.ToInt32(lDR["TeacherJobExperienceKey"]))
                {
                    lDR["PartnerSchool"] = txtPartnerSchool.Text;
                    lDR["StartDate"] = objStartDate;
                    lDR["EndDate"] = objEndDate;
                    lDR["LevelTaught"] = txtLevelTaught.Text;
                    lDR["BasicSalary"] = Convert.ToDouble(txtBasicSalary.Text);
                    lDR["Remarks"] = txtDescription.Text;
                    lDR["Status"] = "Edit";

                }
            }
            lDT.AcceptChanges();
            dgExperienceBrowse.EditIndex = -1;
            dgExperienceBrowse.DataSource = lDT;
            dgExperienceBrowse.DataBind();


        }


    }

    protected void dgExperienceBrowse_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        if (Request.Params["UserAccountKey"] != null != null)
        {
            _UserAccountKey = Convert.ToInt32(Request.Params["UserAccountKey"]);
        }

        dgExperienceBrowse.EditIndex = -1;

        LoadTeacherInfo(_UserAccountKey);

    }    

    protected void dgExperienceBrowse_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label Status = (Label)e.Row.FindControl("lblStatus");
            if (Status.Text == "Delete")
            {
                e.Row.Visible = false;
            }

        }
    }     

    protected void dgExperienceBrowse_SelectedIndexChanged(object sender, EventArgs e)
    {
        ClearJobExperienceRecord();
        btnAdd.Text = "Update";
        tbcEntry.ActiveTab = tbpInfo3;
        if (dgExperienceBrowse.SelectedIndex >= 0)
        {
            DataKey _selectedDataKey = dgExperienceBrowse.SelectedDataKey;
            int _TeacherJobExperienceKey = Convert.ToInt32(_selectedDataKey[0]);
            //int _UserAccountKey = Convert.ToInt32(_selectedDataKey[1]);

            if (_TeacherJobExperienceKey > 0)
            {
                GridViewRow _selectedRow = dgExperienceBrowse.SelectedRow;

                LinkButton lnkEdit = (LinkButton)_selectedRow.FindControl("lnkbtnEdit");
                lnkEdit.Enabled = false;

                LinkButton lnkDelete = (LinkButton)_selectedRow.FindControl("lnkbtnDelete");
                lnkDelete.Enabled = false;

                TeacherJobExperiencesTable _jobExperience = TeacherJobExperiencesTableManager.GetItem(_TeacherJobExperienceKey);
                lblJobExperienceKey.Text = Convert.ToString(_jobExperience.TeacherJobExperienceKey);
                lblAccountKey.Text = Convert.ToString(_jobExperience.UserAccountKey);
                txtPartnerSchool.Text = Convert.ToString(_jobExperience.PartnerSchool);
                DateTime startDate = Convert.ToDateTime(_jobExperience.StartDate);
                txtStartDate.Text = startDate.ToString("dd/MM/yyyy");
                DateTime EndDate = Convert.ToDateTime(_jobExperience.EndDate);
                txtEndDate.Text = EndDate.ToString("dd/MM/yyyy");
                txtLevelTaught.Text = Convert.ToString(_jobExperience.LevelTaught);
                txtSalary.Text = Convert.ToDecimal(_jobExperience.BasicSalary).ToString("0.00");
                txtRefereeName.Text = Convert.ToString(_jobExperience.RefereeName) == null ? string.Empty : Convert.ToString(_jobExperience.RefereeName);
                txtRefereeAddress.Text = Convert.ToString(_jobExperience.RefereeAddress) == null ? string.Empty : Convert.ToString(_jobExperience.RefereeAddress);
                txtRefereeContact.Text = Convert.ToString(_jobExperience.RefereeContact) == null ? string.Empty : Convert.ToString(_jobExperience.RefereeContact);
                txtRefereeEmail.Text = Convert.ToString(_jobExperience.RefereeEmail) == null ? string.Empty : Convert.ToString(_jobExperience.RefereeEmail);
                txtRemarks.Text = Convert.ToString(_jobExperience.Remarks);



                //DataTable lDT = new DataTable();
                //lDT = (DataTable)Session["JobExperiencesDT"];
                //foreach (DataRow lDR in lDT.Rows)
                //{
                //    if (Convert.ToInt32(lDR["TeacherJobExperienceKey"]) == _TeacherJobExperienceKey)
                //    {
                //        lblJobExperienceKey.Text = Convert.ToString(lDR["TeacherJobExperienceKey"]);
                //        lblAccountKey.Text = Convert.ToString(lDR["UserAccountKey"]);
                //        txtPartnerSchool.Text = Convert.ToString(lDR["PartnerSchool"]);
                //        DateTime startDate = Convert.ToDateTime(lDR["StartDate"]);
                //        txtStartDate.Text = startDate.ToString("dd/MM/yyyy");
                //        DateTime EndDate = Convert.ToDateTime(lDR["EndDate"]);
                //        txtEndDate.Text = EndDate.ToString("dd/MM/yyyy");
                //        txtLevelTaught.Text = Convert.ToString(lDR["LevelTaught"]);
                //        txtSalary.Text = Convert.ToDecimal(lDR["BasicSalary"]).ToString("0.00");
                //        txtRefereeName.Text = Convert.ToString(lDR["RefereeName"]) == null ? string.Empty : Convert.ToString(lDR["RefereeName"]);
                //        txtRefereeAddress.Text = Convert.ToString(lDR["RefereeAddress"]) == null ? string.Empty : Convert.ToString(lDR["RefereeAddress"]);
                //        txtRefereeContact.Text = Convert.ToString(lDR["RefereeContact"]) == null ? string.Empty : Convert.ToString(lDR["RefereeContact"]);
                //        txtRefereeEmail.Text = Convert.ToString(lDR["RefereeEmail"]) == null ? string.Empty : Convert.ToString(lDR["RefereeEmail"]);
                //        txtRemarks.Text = Convert.ToString(lDR["Remarks"]);
                //    }
                //}

            }
        }
    }

    protected void dgvTeacherQualtification_SelectedIndexChanged(object sender, EventArgs e)
    {
        ClearQualificationRecord();
        btnQualifyAdd.Text = "Update";
        tbcEntry.ActiveTab = tbpInfo4;
        if (dgvTeacherQualtification.SelectedIndex >= 0)
        {
            DataKey _selectedDataKey = dgvTeacherQualtification.SelectedDataKey;
            int _TeacherJobQualificationKey = Convert.ToInt32(_selectedDataKey[0]);
            //int _UserAccountKey = Convert.ToInt32(_selectedDataKey[1]);

            if (_TeacherJobQualificationKey > 0)
            {
                GridViewRow _selectedRow = dgvTeacherQualtification.SelectedRow;

                LinkButton lnkEdit = (LinkButton)_selectedRow.FindControl("lnkbtnEdit");
                lnkEdit.Enabled = false;

                LinkButton lnkDelete = (LinkButton)_selectedRow.FindControl("lnkbtnDelete");
                lnkDelete.Enabled = false;

                TeacherQualtificationTable _TeacherQualification = TeacherQualtificationTableManager.GetItem(_TeacherJobQualificationKey);
                lblQualificationKey.Text = Convert.ToString(_TeacherQualification.TeacherQualtificationKey);
                lblAccountKey.Text = Convert.ToString(_TeacherQualification.UserAccountKey);
                txtQualification2.Text = Convert.ToString(_TeacherQualification.QualificationName);
                txtOrganization.Text = Convert.ToString(_TeacherQualification.Organization);
                txtYear.Text = Convert.ToString(_TeacherQualification.Year);
                txtGradelevel.Text = Convert.ToString(_TeacherQualification.GradeLevel);
                txtQualifyOthers.Text = Convert.ToString(_TeacherQualification.Others);


                //DataTable lDT = new DataTable();
                //lDT = (DataTable)Session["QualificationDT"];
                //foreach (DataRow lDR in lDT.Rows)
                //{
                //    if (Convert.ToInt32(lDR["TeacherQualtificationKey"]) == _TeacherJobQualificationKey)
                //    {
                //        lblQualificationKey.Text = Convert.ToString(lDR["TeacherQualtificationKey"]);
                //        lblAccountKey.Text = Convert.ToString(lDR["UserAccountKey"]);
                //        txtQualification2.Text = Convert.ToString(lDR["QualificationName"]);
                //        txtOrganization.Text = Convert.ToString(lDR["Organization"]);
                //        txtYear.Text = Convert.ToString(lDR["Year"]);
                //        txtGradelevel.Text = Convert.ToString(lDR["GradeLevel"]);
                //        txtQualifyOthers.Text = Convert.ToString(lDR["Others"]);
                //    }
                //}

            }
        }
    }

    protected void dgvTeacherQualtification_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

        int TeacherQualificationKey = Convert.ToInt32(dgvTeacherQualtification.DataKeys[e.RowIndex].Value);
        int UserAccountKey = Convert.ToInt32(lblUserAccountKey.Text);
        
        if (TeacherQualtificationTableManager.Delete(TeacherQualificationKey))
        {
            lblMessage.Text = "Teacher Qualification deleted";
        }
        else
        {
            lblMessage.Text = "Teacher Qualification Deleted Fail";
        }

        //DataTable lDT = new DataTable();
        //lDT = (DataTable)Session["QualificationDT"];
        //foreach (DataRow lDR in lDT.Rows)
        //{
        //    if (TeacherQualificationKey == Convert.ToInt32(lDR["TeacherQualtificationKey"]))
        //    {
        //        lDR["Status"] = "Delete";
        //    }
        //}
        //lDT.AcceptChanges();
        TeacherQualtificationTableList _TeacherQualificationList = TeacherQualtificationTableManager.GetList(UserAccountKey);
        dgvTeacherQualtification.EditIndex = -1;
        dgvTeacherQualtification.DataSource = _TeacherQualificationList;
        dgvTeacherQualtification.DataBind();
        tbcEntry.ActiveTab = tbpInfo4;

    }

    protected void dgvTeacherQualtification_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label Status = (Label)e.Row.FindControl("lblStatus");
            if (Status.Text == "Delete")
            {
                e.Row.Visible = false;
            }

        }
    }

    protected void gvTeacherOtherSkills_SelectedIndexChanged(object sender, EventArgs e)
    {
        ClearOtherSkillRecord();
        btnSkillAdd.Text = "Update";
        tbcEntry.ActiveTab = tbpInfo5;
        if (gvTeacherOtherSkills.SelectedIndex >= 0)
        {
            DataKey _selectedDataKey = gvTeacherOtherSkills.SelectedDataKey;
            int _TeacherOtherSkillsKey = Convert.ToInt32(_selectedDataKey[0]);
            //int _UserAccountKey = Convert.ToInt32(_selectedDataKey[1]);

            if (_TeacherOtherSkillsKey > 0)
            {
                GridViewRow _selectedRow = gvTeacherOtherSkills.SelectedRow;

                LinkButton lnkEdit = (LinkButton)_selectedRow.FindControl("lnkbtnEdit");
                lnkEdit.Enabled = false;

                LinkButton lnkDelete = (LinkButton)_selectedRow.FindControl("lnkbtnDelete");
                lnkDelete.Enabled = false;

                TeacherOtherSkillsTable _TeacherOtherSkill = TeacherOtherSkillsTableManager.GetItem(_TeacherOtherSkillsKey);
                lblSkillKey.Text = Convert.ToString(_TeacherOtherSkill.TeacherOtherSkillsKey);
                lblAccountKey.Text = Convert.ToString(_TeacherOtherSkill.UserAccountKey);
                txtSkill.Text = Convert.ToString(_TeacherOtherSkill.SkillName);
                txtSkillOrganization.Text = Convert.ToString(_TeacherOtherSkill.Organization);
                txtNoOfYear.Text = Convert.ToString(_TeacherOtherSkill.NoOfYear);
                txtSkillLevel.Text = Convert.ToString(_TeacherOtherSkill.SkillLevel);
                txtSkillOthers.Text = Convert.ToString(_TeacherOtherSkill.Others);

                //DataTable lDT = new DataTable();
                //lDT = (DataTable)Session["TeacherOtherSkillsDT"];
                //foreach (DataRow lDR in lDT.Rows)
                //{
                //    if (Convert.ToInt32(lDR["TeacherOtherSkillsKey"]) == _TeacherOtherSkillsKey)
                //    {
                //        lblSkillKey.Text = Convert.ToString(lDR["TeacherOtherSkillsKey"]);
                //        lblAccountKey.Text = Convert.ToString(lDR["UserAccountKey"]);
                //        txtSkill.Text = Convert.ToString(lDR["SkillName"]);
                //        txtSkillOrganization.Text = Convert.ToString(lDR["Organization"]);
                //        txtNoOfYear.Text = Convert.ToString(lDR["NoOfYear"]);
                //        txtSkillLevel.Text = Convert.ToString(lDR["SkillLevel"]);
                //        txtSkillOthers.Text = Convert.ToString(lDR["Others"]);
                //    }
                //}

            }
        }
    }

    protected void gvTeacherOtherSkills_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

        int TeacherOtherSkillsKey = Convert.ToInt32(gvTeacherOtherSkills.DataKeys[e.RowIndex].Value);
        int UserAccountKey = Convert.ToInt32(lblUserAccountKey.Text);

        if (TeacherOtherSkillsTableManager.Delete(TeacherOtherSkillsKey))
        {
            lblMessage.Text = "Teacher Other Skill deleted";
        }
        else
        {
            lblMessage.Text = "Teacher Ohter Skill Deleted Fail";
        }
        //DataTable lDT = new DataTable();
        //lDT = (DataTable)Session["TeacherOtherSkillsDT"];
        //foreach (DataRow lDR in lDT.Rows)
        //{
        //    if (TeacherOtherSkillsKey == Convert.ToInt32(lDR["TeacherOtherSkillsKey"]))
        //    {
        //        lDR["Status"] = "Delete";
        //    }
        //}
        //lDT.AcceptChanges();
        TeacherOtherSkillsTableList _sTeacherOtherSkillList = TeacherOtherSkillsTableManager.GetList(UserAccountKey);
        gvTeacherOtherSkills.EditIndex = -1;
        gvTeacherOtherSkills.DataSource = _sTeacherOtherSkillList;
        gvTeacherOtherSkills.DataBind();
        tbcEntry.ActiveTab = tbpInfo5;

    }

    protected void gvTeacherOtherSkills_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label Status = (Label)e.Row.FindControl("lblStatus");
            if (Status.Text == "Delete")
            {
                e.Row.Visible = false;
            }

        }
    }

    protected void gvDesignation_SelectedIndexChanged(object sender, EventArgs e)
    {
        ClearDesignationRecord();
        btnDesignationAdd.Text = "Update";
        tbcEntry.ActiveTab = tbpDesignation;
        if (gvDesignation.SelectedIndex >= 0)
        {
            DataKey _selectedDataKey = gvDesignation.SelectedDataKey;
            int _TeacherDesignationKey = Convert.ToInt32(_selectedDataKey[0]);
            //int _UserAccountKey = Convert.ToInt32(_selectedDataKey[1]);

            if (_TeacherDesignationKey > 0)
            {
                GridViewRow _selectedRow = gvDesignation.SelectedRow;

                LinkButton lnkEdit = (LinkButton)_selectedRow.FindControl("lnkbtnEdit");
                lnkEdit.Enabled = false;

                LinkButton lnkDelete = (LinkButton)_selectedRow.FindControl("lnkbtnDelete");
                lnkDelete.Enabled = false;

                TeacherDesignationTable _teacherDesignation = TeacherDesignationTableManager.GetItem(_TeacherDesignationKey);

                lblJobDesignationKey.Text = Convert.ToString(_teacherDesignation.TeacherDesignationKey);
                lblAccountKey.Text = Convert.ToString(_teacherDesignation.UserAccountKey);
                ddlJobDesignation.SelectedValue = Convert.ToString(_teacherDesignation.JobDesignationCode);
                txtDesignationDesc.Text = Convert.ToString(_teacherDesignation.JobDescriptionDetail);
                DateTime startDate = Convert.ToDateTime(_teacherDesignation.StartDate);
                txtDesgnationStartDate.Text = startDate.ToString("dd/MM/yyyy");
                DateTime EndDate = Convert.ToDateTime(_teacherDesignation.EndDate);
                txtDesgnationEndDate.Text = EndDate.ToString("dd/MM/yyyy");
                txtDesignationRemark.Text = Convert.ToString(_teacherDesignation.Remarks);
                chkDesignation.Checked = Convert.ToBoolean(_teacherDesignation.Active);

                //DataTable lDT = new DataTable();
                //lDT = (DataTable)Session["TeacherDesignationsDT"];
                //foreach (DataRow lDR in lDT.Rows)
                //{
                //    if (Convert.ToInt32(lDR["TeacherDesignationKey"]) == _TeacherDesignationKey)
                //    {
                //        
                //    }
                //}

            }
        }
    }

    protected void gvDesignation_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

        int TeacherDesignationKey = Convert.ToInt32(gvDesignation.DataKeys[e.RowIndex].Value);
        int UserAccountKey = Convert.ToInt32(lblUserAccountKey.Text);

        if (TeacherDesignationTableManager.Delete(TeacherDesignationKey))
        {
            lblMessage.Text = "Teacher Other Skill deleted";
        }
        else
        {
            lblMessage.Text = "Teacher Ohter Skill Deleted Fail";
        }
        //DataTable lDT = new DataTable();
        //lDT = (DataTable)Session["TeacherDesignationsDT"];
        //foreach (DataRow lDR in lDT.Rows)
        //{
        //    if (TeacherDesignationKey == Convert.ToInt32(lDR["TeacherDesignationKey"]))
        //    {
        //        lDR["Status"] = "Delete";
        //    }
        //}
        //lDT.AcceptChanges();
        TeacherDesignationTableList _sTeacherDesignationList = TeacherDesignationTableManager.GetList(UserAccountKey);
        gvDesignation.EditIndex = -1;
        gvDesignation.DataSource = _sTeacherDesignationList;
        gvDesignation.DataBind();
        tbcEntry.ActiveTab = tbpDesignation;

    }

    protected void gvDesignation_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label Status = (Label)e.Row.FindControl("lblStatus");
            if (Status.Text == "Delete")
            {
                e.Row.Visible = false;
            }

        }
    }

    protected void gvSalary_SelectedIndexChanged(object sender, EventArgs e)
    {
        ClearSalaryRecord();
        btnSalaryAdd.Text = "Update";
        tbcEntry.ActiveTab = tbpSalary;
        if (gvSalary.SelectedIndex >= 0)
        {
            DataKey _selectedDataKey = gvSalary.SelectedDataKey;
            int _TeacherSalaryKey = Convert.ToInt32(_selectedDataKey[0]);            

            if (_TeacherSalaryKey > 0)
            {
                GridViewRow _selectedRow = gvSalary.SelectedRow;

                LinkButton lnkEdit = (LinkButton)_selectedRow.FindControl("lnkbtnEdit");
                lnkEdit.Enabled = false;

                LinkButton lnkDelete = (LinkButton)_selectedRow.FindControl("lnkbtnDelete");
                lnkDelete.Enabled = false;

                TeacherSalaryTable _teacherSalary = TeacherSalaryTableManager.GetItem(_TeacherSalaryKey);
                lblSalaryKey.Text = Convert.ToString(_teacherSalary.TeacherSalaryKey);
                lblAccountKey.Text = Convert.ToString(_teacherSalary.UserAccountKey);
                ddlpaymentType.SelectedValue = Convert.ToString(_teacherSalary.PaymentTypeCode);
                DateTime startDate = Convert.ToDateTime(_teacherSalary.StartDate);
                txtSalaryStartDate.Text = startDate.ToString("dd/MM/yyyy");
                DateTime EndDate = Convert.ToDateTime(_teacherSalary.EndDate);
                txtSalaryEndDate.Text = EndDate.ToString("dd/MM/yyyy");
                txtAmount.Text = Convert.ToDecimal(_teacherSalary.Amount) == 0 ? string.Empty : Convert.ToDecimal(_teacherSalary.Amount).ToString("0.00");
                txtAllotment1.Text = Convert.ToDecimal(_teacherSalary.Allotment1) == 0 ? string.Empty : Convert.ToDecimal(_teacherSalary.Allotment1).ToString("0.00");
                txtAllotment2.Text = Convert.ToDecimal(_teacherSalary.Allotment2) == 0 ? string.Empty : Convert.ToDecimal(_teacherSalary.Allotment2).ToString("0.00");//Convert.ToDecimal(lDR["Allotment2"]).ToString("0.00");
                txtSalaryRemark.Text = Convert.ToString(_teacherSalary.Remarks);
                chkActive.Checked = Convert.ToBoolean(_teacherSalary.Active);                 

            }
        }
    }

    protected void gvSalary_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

        int TeacherSalaryKey = Convert.ToInt32(gvSalary.DataKeys[e.RowIndex].Value);

        int UserAccountKey = Convert.ToInt32(lblUserAccountKey.Text);

        if (TeacherSalaryTableManager.Delete(TeacherSalaryKey))
        {
            lblMessage.Text = "Teacher Salary deleted";
        }
        else
        {
            lblMessage.Text = "Teacher Salary Deleted Fail";
        }
        
        TeacherSalaryTransTableList _sTeacherSalaryList = TeacherSalaryTransTableManager.GetList(UserAccountKey);
        
        gvSalary.EditIndex = -1;
        gvSalary.DataSource = _sTeacherSalaryList;
        gvSalary.DataBind();
        tbcEntry.ActiveTab = tbpSalary;

    }

    protected void gvSalary_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label Status = (Label)e.Row.FindControl("lblStatus");
            if (Status.Text == "Delete")
            {
                e.Row.Visible = false;
            }

        }
        tbcEntry.ActiveTab = tbpSalary;
    }

    protected void btnUpdatePhoto_Click(object sender, EventArgs e)
    {
        Response.Redirect("photo-upload.aspx?id=" + lblUserAccountKey.Text);
    }

    protected void ddlTSSubjectList_SelectedIndexChanged(object sender, EventArgs e)
    {
        TeacherSubjectTable _ts = new TeacherSubjectTable();
        _ts = TeacherSubjectTableManager.GetItem(Convert.ToInt32(lblTeacherProfileKey.Text), Convert.ToInt32(ddlTSSubjectList.Text));

        if (_ts != null)
        {
            lblTeacherSubjectKey.Text = _ts.TeacherSubjectKey.ToString();
            txtTSDescription.Text = _ts.Description;
            btnDeleteTeacherSubject.Enabled = true;
        }
        else
        {
            lblTeacherSubjectKey.Text = "-1";
            txtTSDescription.Text = string.Empty;
            btnDeleteTeacherSubject.Enabled = false;
        }

        tbcEntry.ActiveTab = tbpSubjects;
    }

    protected void gvTeacherSubject_SelectedIndexChanged(object sender, EventArgs e)
    {
        tbcEntry.ActiveTab = tbpSubjects;
    }

    protected void btnDeleteTeacherSubject_Click(object sender, EventArgs e)
    {
        if (Convert.ToInt32(lblTeacherSubjectKey.Text) > 0)
        {
            TeacherSubjectTableManager.Delete(Convert.ToInt32(lblTeacherSubjectKey.Text));
            gvTeacherSubject.DataBind();
            txtTSDescription.Text = string.Empty;
            lblTeacherSubjectKey.Text = "-1";
            tbcEntry.ActiveTab = tbpSubjects;
        }
    }

    protected void btnAddTeacherSubject_Click(object sender, EventArgs e)
    {
        if (ddlTSSubjectList.SelectedIndex >= 0)
        {
            TeacherSubjectTable _ts = new TeacherSubjectTable();
            _ts.TeacherSubjectKey = Convert.ToInt32(lblTeacherSubjectKey.Text);
            _ts.TeacherProfileKey = Convert.ToInt32(lblTeacherProfileKey.Text);
            _ts.SubjectKey = Convert.ToInt32(ddlTSSubjectList.Text);
            _ts.Description = txtTSDescription.Text;
            _ts.Status = true;

            if (TeacherSubjectTableManager.Save(_ts) > 0)
            {
                lblTeacherSubjectKey.Text = _ts.TeacherSubjectKey.ToString();
            }

            gvTeacherSubject.DataBind();
            tbcEntry.ActiveTab = tbpSubjects;
        }
    }
    #endregion

    #region "Methods

    private void ClearJobExperienceRecord()
    {
        txtPartnerSchool.Text = string.Empty;
        txtStartDate.Text = string.Empty;
        txtEndDate.Text = string.Empty;
        txtLevelTaught.Text = string.Empty;
        txtSalary.Text = string.Empty;
        txtRemarks.Text = string.Empty;
        txtRefereeName.Text = string.Empty;
        txtRefereeAddress.Text = string.Empty;
        txtRefereeContact.Text = string.Empty;
        txtRefereeEmail.Text = string.Empty;
    }

    private void UpdateTempTable(string TeacherJobExperienceKey, string UserAccountKeyString, string PartnerSchool, string dStartDate, string dEndDate, string LevelTaught, decimal BasicSalary, string RefereeName, string RefereeAddress, string RefereeEmail, string RefereeContact, string Remarks)
    {
        int JobExperienceKey = Convert.ToInt32(TeacherJobExperienceKey);
        int UserAccountKey = Convert.ToInt32(UserAccountKeyString);
        //TextBox txtPartnerSchool = (TextBox)dgExperienceBrowse.Rows[e.RowIndex].FindControl("txtPartnerSchool1");
        string txtStartDate = dStartDate;
        var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
        DateTime objStartDate = Convert.ToDateTime(txtStartDate, dtfi1);
        string txtEndDate = dEndDate;
        var dtfi2 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
        DateTime objEndDate = Convert.ToDateTime(txtEndDate, dtfi1);
        DataTable lDT = new DataTable();
        lDT = (DataTable)Session["JobExperiencesDT"];
        foreach (DataRow lDR in lDT.Rows)
        {
            if (JobExperienceKey == Convert.ToInt32(lDR["TeacherJobExperienceKey"]))
            {
                lDR["PartnerSchool"] = txtPartnerSchool.Text;
                lDR["StartDate"] = objStartDate;
                lDR["EndDate"] = objEndDate;
                lDR["LevelTaught"] = LevelTaught;
                lDR["BasicSalary"] = BasicSalary.Equals(string.Empty) ? 0 : Convert.ToDecimal(BasicSalary);
                lDR["RefereeName"] = Convert.ToString(RefereeName);
                lDR["RefereeAddress"] = Convert.ToString(RefereeAddress);
                lDR["RefereeEmail"] = Convert.ToString(RefereeEmail);
                lDR["RefereeContact"] = Convert.ToString(RefereeContact);
                lDR["Remarks"] = Remarks;
                lDR["Status"] = "Edit";

            }
        }
        lDT.AcceptChanges();
        dgExperienceBrowse.EditIndex = -1;
        dgExperienceBrowse.DataSource = lDT;
        dgExperienceBrowse.DataBind();
        ClearJobExperienceRecord();
        btnAdd.Text = "Add New";
    }

    private void AddToTempTable(String PartnerSchool, string dStartDate, string dEndDate, string LevelTaught, string BasicSalary, string RefereeName, string RefereeAddress, string RefereeEmail, string RefereeContact, string Remarks)
    {

        DataTable lDT = new DataTable();
        lDT = (DataTable)Session["JobExperiencesDT"];
        int count = lDT.Rows.Count;

        DataRow dataRow = lDT.NewRow();
        dataRow["TeacherJobExperienceKey"] = count + 1;
        dataRow["UserAccountKey"] = 0;
        dataRow["PartnerSchool"] = PartnerSchool;
        string StartDate = dStartDate;
        var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
        DateTime objStartDate = Convert.ToDateTime(StartDate, dtfi1);
        dataRow["StartDate"] = objStartDate;
        string EndDate = dEndDate;
        var dtfi2 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
        DateTime objEndDate = Convert.ToDateTime(EndDate, dtfi2);
        dataRow["EndDate"] = objEndDate;
        dataRow["LevelTaught"] = LevelTaught;
        dataRow["BasicSalary"] = BasicSalary.Equals(string.Empty) ? 0 : Convert.ToDecimal(BasicSalary);
        dataRow["RefereeName"] = RefereeName;
        dataRow["RefereeAddress"] = RefereeAddress;
        dataRow["RefereeEmail"] = RefereeEmail;
        dataRow["RefereeContact"] = RefereeContact;
        dataRow["Remarks"] = Remarks;
        dataRow["Status"] = "New";
        lDT.Rows.Add(dataRow);
        Session["JobExperiencesDT"] = lDT;
        lDT.AcceptChanges();
        dgExperienceBrowse.EditIndex = -1;
        dgExperienceBrowse.DataSource = lDT;
        dgExperienceBrowse.DataBind();
        ClearJobExperienceRecord();

    }

    protected void TeacherContactNumbers_ServerSideValidate(object source, ServerValidateEventArgs args)
    {
        bool _retValue = true;


        args.IsValid = _retValue;
    }

    protected void TeacherDOB_ServerSideValidation(object source, ServerValidateEventArgs args)
    {
         

        bool _retValue = true;
        DateTime _dtDOB = DateTime.Now;
        string _strDOB = string.Empty;

        if (ddlDOBDay.Text != "-1" && ddlDOBMonth.Text != "-1" && ddlDOBYear.Text != "-1")
        {
            _strDOB = ddlDOBDay.Text + "/" + ddlDOBMonth.SelectedItem.Text + "/" + ddlDOBYear.Text.ToString();
            if (!SIS.Utilities.General.GetDateTime(_strDOB, out _dtDOB))
            {

                lblMessage.Text += _strDOB + "  " + " Family Memeber's DOB is invalid!<br/>";
                _retValue = false;
            }
            else
            {
                _retValue = true;                
            }
        }
        else
        {
            lblMessage.Text += "Select Valid Teacher DOB.<br/>";
            _retValue = false;
        }
        args.IsValid = _retValue;
    }

    protected void JobExperienceEndDate_ServerSideValidation(object source, ServerValidateEventArgs args)
    {

        bool _retValue = true;
        string StartDate = txtStartDate.Text;
        var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy", DateSeparator = "/" };
        DateTime objStartDate = Convert.ToDateTime(StartDate, dtfi1);
        string EndDate = txtEndDate.Text;
        var dtfi2 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy", DateSeparator = "/" };
        DateTime objEndDate = Convert.ToDateTime(EndDate, dtfi2);

        //DateTime _dEnd = DateTime.Parse(txtEndDate.Text);
        string _strDOB = string.Empty;

        if (!txtEndDate.Text.Equals(string.Empty))
        {
            if (txtStartDate.Text.Equals(string.Empty))
            {
                _retValue = false;
            }
            else if (objStartDate > objEndDate)
            {
                _retValue = false;
            }
        }

        args.IsValid = _retValue;
    }

    protected void DesignationEndDate_ServerSideValidation(object source, ServerValidateEventArgs args)
    {

        bool _retValue = true;
        string StartDate = txtDesgnationStartDate.Text;
        var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy", DateSeparator = "/" };
        DateTime objStartDate = Convert.ToDateTime(StartDate, dtfi1);
        string EndDate = txtDesgnationEndDate.Text;
        var dtfi2 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy", DateSeparator = "/" };
        DateTime objEndDate = Convert.ToDateTime(EndDate, dtfi2);

        //DateTime _dEnd = DateTime.Parse(txtEndDate.Text);
        string _strDOB = string.Empty;

        if (!txtDesgnationEndDate.Text.Equals(string.Empty))
        {
            if (txtDesgnationStartDate.Text.Equals(string.Empty))
            {
                _retValue = false;
            }
            else if (objStartDate > objEndDate)
            {
                _retValue = false;
            }
        }

        args.IsValid = _retValue;
    }

    protected void SalaryEndDate_ServerSideValidation(object source, ServerValidateEventArgs args)
    {

        bool _retValue = true;
        string StartDate = txtSalaryStartDate.Text;
        var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy", DateSeparator = "/" };
        DateTime objStartDate = Convert.ToDateTime(StartDate, dtfi1);
        string EndDate = txtSalaryEndDate.Text;
        var dtfi2 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy", DateSeparator = "/" };
        DateTime objEndDate = Convert.ToDateTime(EndDate, dtfi2);

        //DateTime _dEnd = DateTime.Parse(txtEndDate.Text);
        string _strDOB = string.Empty;

        if (!txtSalaryEndDate.Text.Equals(string.Empty))
        {
            if (txtSalaryStartDate.Text.Equals(string.Empty))
            {
                _retValue = false;
            }
            else if (objStartDate > objEndDate)
            {
                _retValue = false;
            }
        }

        args.IsValid = _retValue;
    }

    private void LoadTeacherInfo(int AccountID)
    {
        UserAccountTable _account = new UserAccountTable();
        _account = UserAccountTableManager.GetItem(AccountID);

        btnUpdatePhoto.Visible = false;

        if (_account == null)
        {
            lblTopMessage.Text = "Teacher account ID (" + AccountID.ToString() + ") is not found!";
        }
        else if (_account.UserAccountKey <= 0)
        {
            lblTopMessage.Text = "Teacher account ID is not found!";
        }

        if (_account != null && _account.UserAccountKey > 0)
        {
            if (_account.UserAccountTypeCode != 200)
            {
                lblTopMessage.Text = "Only for Teacher account ID will be loaded.";
                return;
            }

            lblUserAccountKey.Text = _account.UserAccountKey.ToString();
            ddlSchoolList.Text = _account.SchoolKey.ToString();
            TeacherProfileTable _sprofile = new TeacherProfileTable();
            TeacherAddressTable _sraddress = new TeacherAddressTable();
            TeacherAddressTable _spaddress = new TeacherAddressTable();
            TeacherJobExperiencesTableList _sJobExperiencesList = new TeacherJobExperiencesTableList();
            TeacherDesignationTableList _sTeacherDesignationList = new TeacherDesignationTableList();
            TeacherSalaryTableList _sTeacherSalaryList = new TeacherSalaryTableList();
            TeacherQualtificationTableList _sQualificationList = new TeacherQualtificationTableList();
            TeacherOtherSkillsTableList _sSkillList = new TeacherOtherSkillsTableList();
            TeacherContactTable _scontact = new TeacherContactTable();

            _sprofile = TeacherProfileTableManager.GetItemByUserAccountKey(AccountID, _account.SchoolKey);
            if (_sprofile != null && _sprofile.TeacherProfileKey > 0)
            {
                lblTeacherProfileKey.Text = _sprofile.TeacherProfileKey.ToString();
                txtFirstName.Text = _sprofile.FirstName;
                txtLastName.Text = _sprofile.LastName;
                txtOtherName.Text = _sprofile.OtherName;
                ddlGender.SelectedValue = _sprofile.Gender;
                DateTime _dtDOB = _sprofile.DateOfBirth;
                ddlDOBDay.Text = _dtDOB.Day.ToString("00");
                ddlDOBMonth.Text = _dtDOB.Month.ToString("00");
                ddlDOBYear.Text = _dtDOB.Year.ToString("0000");

                txtNRICNumber.Text = _sprofile.NRICNumber;
                ddlDrivingLicenceType.Text = _sprofile.DrivingLicenceType.ToString();
                txtDrivingLicenceNumber.Text = _sprofile.DrivingLicenseNumber;

                ddlTravelDocType.Text = _sprofile.TravelDocumentType.ToString();
                txtTravelDocNumber.Text = _sprofile.TravelDocumentNumber;

                ddlBloodGroup.Text = _sprofile.BloodGroupCode.ToString();
                ddlMaritalStatus.Text = _sprofile.MartialStatusCode.ToString();
                ddlRaceCode.Text = _sprofile.RaceCode.ToString();
                ddlReligion.Text = _sprofile.ReligionCode.ToString();
                ddlNationality.Text = _sprofile.NationalityCode.ToString();
                txtWebsiteUrl.Text = _sprofile.WebSiteUrl;
                txtHobby.Text = _sprofile.Hobby;
                ddlParentStatus.SelectedValue = _sprofile.ParentStatus.ToString();
                txtPlaceOfBirth.Text = _sprofile.PlaceOfBirth;
                DateTime SignInDate = Convert.ToDateTime(_sprofile.JoinDate);
                if (SignInDate.ToShortDateString() =="1/1/1900")
                { txtJoinDate.Text = ""; }
                else
                { txtJoinDate.Text = SignInDate.ToString("dd/MM/yyyy"); }

                if (_sprofile.Photo != null && _sprofile.Photo.Length > 0)
                {
                    divTeacherPhoto.Visible = true;
                    imgCurrentTeacherPhoto.ImageUrl = "~/images/imagehandler.ashx?key=" + lblTeacherProfileKey.Text + "&type=teacherphoto";
                    hplCurrentTeacherPhoto.NavigateUrl = imgCurrentTeacherPhoto.ImageUrl;
                    imgCurrentTeacherPhoto.Width = 75;
                    imgCurrentTeacherPhoto.Height = 100;
                }
                else
                {
                    divTeacherPhoto.Visible = false;
                    imgCurrentTeacherPhoto.ImageUrl = "";
                    hplCurrentTeacherPhoto.NavigateUrl = "";
                    imgCurrentTeacherPhoto.Width = 0;
                    imgCurrentTeacherPhoto.Height = 0;
                }
                btnUpdatePhoto.Visible = true;
            }

            //Contact Table

            _scontact = TeacherContactTableManager.GetItemByUserAccountKey(AccountID);

            if (_scontact != null && _scontact.TeacherContactKey > 0)
            {
                lblTeacherContactKey.Text = _scontact.TeacherContactKey.ToString();
                txtMobileNumber.Text = _scontact.MobileNumber;
                txtHomePhoneNumber.Text = _scontact.HomePhoneNumber;
                txtOtherContactNumber.Text = _scontact.OtherNumber;
                txtOfficeNumber.Text = _scontact.OfficePhoneNumber;
                txtFaxNumber.Text = _scontact.FaxNumber;
                txtEmailAddress.Text = _scontact.EmailAddress;
            }
            //Resident
            _sraddress = TeacherAddressTableManager.GetItemByUserAccountKey(AccountID, 1);
            if (_sraddress != null && _sraddress.TeacherAddressKey > 0)
            {
                lblTeacherRAddressKey.Text = _sraddress.TeacherAddressKey.ToString();
                txtUnitNo.Text = _sraddress.UnitNo;
                txtStreetName.Text = _sraddress.StreetName;
                ddlCountry.SelectedValue = _sraddress.CountryCode.ToString();
                _common.LoadDistrictCodeDDL(ddlDistrict, Convert.ToInt16(ddlCountry.SelectedItem.Value), string.Empty);
                ddlDistrict.SelectedValue = _sraddress.DistrictCode.ToString();
                _common.LoadCityCodeDDL(ddlCity, Convert.ToInt32(ddlDistrict.SelectedValue), Convert.ToInt16(ddlCountry.SelectedValue), string.Empty);
                ddlCity.SelectedValue = _sraddress.CityCode.ToString();
                txtPostCode.Text = _sraddress.PostalCode;
            }

            //Permanent/Contact
            _spaddress = TeacherAddressTableManager.GetItemByUserAccountKey(AccountID, 2);
            if (_spaddress != null && _spaddress.TeacherAddressKey > 0)
            {
                lblTeacherPAddressKey.Text = _spaddress.TeacherAddressKey.ToString();
                txtPUnitNo.Text = _spaddress.UnitNo;
                txtPStreetName.Text = _spaddress.StreetName;
                ddlPCountry.SelectedValue = _spaddress.CountryCode.ToString();
                _common.LoadDistrictCodeDDL(ddlPDistrict, Convert.ToInt16(ddlPCountry.SelectedItem.Value), string.Empty);
                ddlPDistrict.SelectedValue = _spaddress.DistrictCode.ToString();
                _common.LoadCityCodeDDL(ddlPCity, Convert.ToInt32(ddlPDistrict.SelectedValue), Convert.ToInt16(ddlCountry.SelectedValue), string.Empty);
                ddlPCity.SelectedValue = _spaddress.CityCode.ToString();
                txtPPostCode.Text = _spaddress.PostalCode;
                //chkPSameAsResident.Checked = _spaddress.SameAsResident;
                chkPSameAsResident_CheckedChanged(null, null);
            }

            //Job Experiences
            DataTable lDT = new DataTable();
            _sJobExperiencesList = new TeacherJobExperiencesTableList();
            Int32 ProfileKey = _sprofile.TeacherProfileKey;
            _sJobExperiencesList = TeacherJobExperiencesTableManager.GetList(AccountID);
            //CreateTable(_sJobExperiencesList);
            dgExperienceBrowse.DataSource = _sJobExperiencesList;//Session["JobExperiencesDT"];
            dgExperienceBrowse.DataBind();


            //Designation
            DataTable lDesignationDT = new DataTable();
            _sTeacherDesignationList = new TeacherDesignationTableList();
            _sTeacherDesignationList = TeacherDesignationTableManager.GetList(AccountID);
            //CreateDesignationTable(_sTeacherDesignationList);
            gvDesignation.DataSource = _sTeacherDesignationList;//Session["TeacherDesignationsDT"];
            gvDesignation.DataBind();

            //Salary
            DataTable lSalaryDT = new DataTable();
            _sTeacherSalaryList = new TeacherSalaryTableList();
            _sTeacherSalaryList = TeacherSalaryTableManager.GetList(AccountID);
            //CreateSalaryTable(_sTeacherSalaryList);
            gvSalary.DataSource = _sTeacherSalaryList;//Session["TeacherSalaryDT"];
            gvSalary.DataBind();

            //Designation
            DataTable lQualificationDT = new DataTable();
            _sQualificationList = new TeacherQualtificationTableList();
            _sQualificationList = TeacherQualtificationTableManager.GetList(AccountID);
            //CreateQualifyTable(_sQualificationList);
            dgvTeacherQualtification.DataSource = _sQualificationList;//Session["QualificationDT"];
            dgvTeacherQualtification.DataBind();

            //Designation
            DataTable lSkillDT = new DataTable();
            _sSkillList = new TeacherOtherSkillsTableList();
            _sSkillList = TeacherOtherSkillsTableManager.GetList(AccountID);
            //ateSkillTable(_sSkillList);
            gvTeacherOtherSkills.DataSource = _sSkillList;//Session["TeacherOtherSkillsDT"];
            gvTeacherOtherSkills.DataBind();

            
        }
    }   

    private void ClearOtherSkillRecord()
    {
        txtSkill.Text = string.Empty;
        txtSkillOrganization.Text = string.Empty;
        txtSkillLevel.Text = string.Empty;
        txtSkillOthers.Text = string.Empty;
        txtNoOfYear.Text = string.Empty;
    }

    private void ClearQualificationRecord()
    {
        txtQualification2.Text = string.Empty;
        txtOrganization.Text = string.Empty;
        txtYear.Text = string.Empty;
        txtGradelevel.Text = string.Empty;
        txtQualifyOthers.Text = string.Empty;
    }

    private void ClearSalaryRecord()
    {
        txtAmount.Text = string.Empty;
        txtAllotment1.Text = string.Empty;
        txtAllotment2.Text = string.Empty;
        txtSalaryStartDate.Text = string.Empty;
        txtSalaryEndDate.Text = string.Empty;
        txtSalaryRemark.Text = string.Empty;
        chkActive.Checked = false;
        ddlCurrency.SelectedIndex = 0;
        ddlpaymentType.SelectedIndex = 0;
    }

    private void ClearDesignationRecord()
    {
        txtDesignationDesc.Text = string.Empty;
        txtDesgnationStartDate.Text = string.Empty;
        txtDesgnationEndDate.Text = string.Empty;
        txtDesignationRemark.Text = string.Empty;
        chkDesignation.Checked = false;
        
    }

    private void FillTeacherSalary(int AccountID)
    {
        DataTable lSalaryDT = new DataTable();
        TeacherSalaryTableList _sTeacherSalaryList = new TeacherSalaryTableList();
        _sTeacherSalaryList = TeacherSalaryTableManager.GetList(AccountID);
        gvSalary.DataSource = _sTeacherSalaryList;
        gvSalary.DataBind();
    }

    private void FillTeacherJobExperience(int AccountID)
    {

        //Job Experiences
        DataTable lDT = new DataTable();
        TeacherJobExperiencesTableList _sJobExperiencesList = new TeacherJobExperiencesTableList();
        _sJobExperiencesList = TeacherJobExperiencesTableManager.GetList(AccountID);
        dgExperienceBrowse.DataSource = _sJobExperiencesList;
        dgExperienceBrowse.DataBind();
    }

    private void FillTeacherOtherSkill(int AccountID)
    {

        //Job Experiences
        DataTable lDT = new DataTable();
        TeacherOtherSkillsTableList _sOtherSkillList = new TeacherOtherSkillsTableList();
        _sOtherSkillList = TeacherOtherSkillsTableManager.GetList(AccountID);
        gvTeacherOtherSkills.DataSource = _sOtherSkillList;
        gvTeacherOtherSkills.DataBind();
    }

    private void FillTeacherDesignation(int AccountID)
    {

        //Job Experiences
        DataTable lDT = new DataTable();
        TeacherDesignationTableList _sDesignationList = new TeacherDesignationTableList();
        _sDesignationList = TeacherDesignationTableManager.GetList(AccountID);
        gvDesignation.DataSource = _sDesignationList;
        gvDesignation.DataBind();
    }

    private void FillTeacherQualification(int AccountID)
    {

        //Job Experiences
        DataTable lDT = new DataTable();
        TeacherQualtificationTableList _sQualificationList = new TeacherQualtificationTableList();
        _sQualificationList = TeacherQualtificationTableManager.GetList(AccountID);
        dgvTeacherQualtification.DataSource = _sQualificationList;
        dgvTeacherQualtification.DataBind();
    }    

    #endregion


    #region "No Used Methods"
    //private void CreateTable(TeacherJobExperiencesTableList _sJobExperiencesList)
    //{
    //    // create DataTable object
    //    DataTable JobExperienceDataTable = new DataTable();
    //    Session["JobExperiencesDT"] = JobExperienceDataTable;

    //    // auto increment column for productsDataTable
    //    DataColumn dataColumn = new DataColumn("TeacherJobExperienceKey", System.Type.GetType("System.Int32"));
    //    dataColumn.AutoIncrement = true;
    //    dataColumn.AutoIncrementSeed = 1;
    //    dataColumn.AutoIncrementStep = 1;
    //    //dataColumn.Unique = true;
    //    JobExperienceDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("UserAccountKey", System.Type.GetType("System.Int32"));
    //    JobExperienceDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("PartnerSchool", System.Type.GetType("System.String"));
    //    JobExperienceDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("StartDate", System.Type.GetType("System.DateTime"));
    //    JobExperienceDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("EndDate", System.Type.GetType("System.DateTime"));
    //    JobExperienceDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("LevelTaught", System.Type.GetType("System.String"));
    //    JobExperienceDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("BasicSalary", System.Type.GetType("System.Double"));
    //    JobExperienceDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("RefereeName", System.Type.GetType("System.String"));
    //    JobExperienceDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("RefereeAddress", System.Type.GetType("System.String"));
    //    JobExperienceDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("RefereeEmail", System.Type.GetType("System.String"));
    //    JobExperienceDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("RefereeContact", System.Type.GetType("System.String"));
    //    JobExperienceDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("Remarks", System.Type.GetType("System.String"));
    //    JobExperienceDataTable.Columns.Add(dataColumn);
    //    //Remarks

    //    dataColumn = new DataColumn("Status", System.Type.GetType("System.String"));
    //    JobExperienceDataTable.Columns.Add(dataColumn);
    //    //Remarks

    //    // After Creating columns you can add data rows to store the data dynamically

    //    for (int i = 0; i < _sJobExperiencesList.Count; i++)
    //    {

    //        DataRow dataRow = JobExperienceDataTable.NewRow();
    //        dataRow["TeacherJobExperienceKey"] = _sJobExperiencesList[i].TeacherJobExperienceKey;
    //        dataRow["UserAccountKey"] = _sJobExperiencesList[i].UserAccountKey;
    //        dataRow["PartnerSchool"] = _sJobExperiencesList[i].PartnerSchool;
    //        dataRow["StartDate"] = _sJobExperiencesList[i].StartDate;
    //        dataRow["EndDate"] = _sJobExperiencesList[i].EndDate;
    //        dataRow["LevelTaught"] = _sJobExperiencesList[i].LevelTaught;
    //        dataRow["BasicSalary"] = _sJobExperiencesList[i].BasicSalary;
    //        dataRow["RefereeName"] = _sJobExperiencesList[i].RefereeName;
    //        dataRow["RefereeAddress"] = _sJobExperiencesList[i].RefereeAddress;
    //        dataRow["RefereeEmail"] = _sJobExperiencesList[i].RefereeEmail;
    //        dataRow["RefereeContact"] = _sJobExperiencesList[i].RefereeContact;
    //        dataRow["Remarks"] = _sJobExperiencesList[i].Remarks;
    //        dataRow["Status"] = "Old";
    //        JobExperienceDataTable.Rows.Add(dataRow);
    //    }

    //    Session["JobExperiencesDT"] = JobExperienceDataTable;
    //}

    //private void CreateSalaryTable(TeacherSalaryTableList _sTeacherSalaryList)
    //{
    //    // create DataTable object
    //    DataTable SalaryDataTable = new DataTable();
    //    Session["TeacherSalaryDT"] = SalaryDataTable;
    //    // auto increment column for productsDataTable
    //    DataColumn dataColumn = new DataColumn("TeacherSalaryKey", System.Type.GetType("System.Int32"));
    //    dataColumn.AutoIncrement = true;
    //    dataColumn.AutoIncrementSeed = 1;
    //    dataColumn.AutoIncrementStep = 1;
    //    //dataColumn.Unique = true;
    //    SalaryDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("UserAccountKey", System.Type.GetType("System.Int32"));
    //    SalaryDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("PaymentTypeCode", System.Type.GetType("System.Int16"));
    //    SalaryDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("Amount", System.Type.GetType("System.Decimal"));
    //    SalaryDataTable.Columns.Add(dataColumn);
    //    //
    //    dataColumn = new DataColumn("Allotment1", System.Type.GetType("System.Decimal"));
    //    SalaryDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("Allotment2", System.Type.GetType("System.Decimal"));
    //    SalaryDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("CurrencyCode", System.Type.GetType("System.Int16"));
    //    SalaryDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("StartDate", System.Type.GetType("System.DateTime"));
    //    SalaryDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("EndDate", System.Type.GetType("System.DateTime"));
    //    SalaryDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("Active", System.Type.GetType("System.Boolean"));
    //    SalaryDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("Remarks", System.Type.GetType("System.String"));
    //    SalaryDataTable.Columns.Add(dataColumn);


    //    dataColumn = new DataColumn("Status", System.Type.GetType("System.String"));
    //    SalaryDataTable.Columns.Add(dataColumn);


    //    // After Creating columns you can add data rows to store the data dynamically

    //    for (int i = 0; i < _sTeacherSalaryList.Count; i++)
    //    {

    //        DataRow dataRow = SalaryDataTable.NewRow();
    //        dataRow["TeacherSalaryKey"] = _sTeacherSalaryList[i].TeacherSalaryKey;
    //        dataRow["UserAccountKey"] = _sTeacherSalaryList[i].UserAccountKey;
    //        dataRow["PaymentTypeCode"] = _sTeacherSalaryList[i].PaymentTypeCode;
    //        dataRow["Amount"] = _sTeacherSalaryList[i].Amount;
    //        dataRow["Allotment1"] = _sTeacherSalaryList[i].Allotment1;
    //        dataRow["Allotment2"] = _sTeacherSalaryList[i].Allotment2;
    //        dataRow["CurrencyCode"] = _sTeacherSalaryList[i].CurrencyCode;
    //        dataRow["StartDate"] = _sTeacherSalaryList[i].StartDate;
    //        dataRow["EndDate"] = _sTeacherSalaryList[i].EndDate;
    //        dataRow["Active"] = _sTeacherSalaryList[i].Active;
    //        dataRow["Remarks"] = _sTeacherSalaryList[i].Remarks;
    //        dataRow["Status"] = "Old";
    //        SalaryDataTable.Rows.Add(dataRow);
    //    }

    //    Session["TeacherSalaryDT"] = SalaryDataTable;
    //}

    //private void CreateDesignationTable(TeacherDesignationTableList _sTeacherDesignationList)
    //{
    //    // create DataTable object
    //    DataTable DesignationDataTable = new DataTable();
    //    Session["TeacherDesignationsDT"] = DesignationDataTable;

    //    // auto increment column for productsDataTable
    //    DataColumn dataColumn = new DataColumn("TeacherDesignationKey", System.Type.GetType("System.Int32"));
    //    dataColumn.AutoIncrement = true;
    //    dataColumn.AutoIncrementSeed = 1;
    //    dataColumn.AutoIncrementStep = 1;
    //    //dataColumn.Unique = true;
    //    DesignationDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("UserAccountKey", System.Type.GetType("System.Int32"));
    //    DesignationDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("JobDesignationCode", System.Type.GetType("System.Int16"));
    //    DesignationDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("JobDescriptionDetail", System.Type.GetType("System.String"));
    //    DesignationDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("StartDate", System.Type.GetType("System.DateTime"));
    //    DesignationDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("EndDate", System.Type.GetType("System.DateTime"));
    //    DesignationDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("Active", System.Type.GetType("System.Boolean"));
    //    DesignationDataTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("Remarks", System.Type.GetType("System.String"));
    //    DesignationDataTable.Columns.Add(dataColumn);


    //    dataColumn = new DataColumn("Status", System.Type.GetType("System.String"));
    //    DesignationDataTable.Columns.Add(dataColumn);


    //    // After Creating columns you can add data rows to store the data dynamically

    //    for (int i = 0; i < _sTeacherDesignationList.Count; i++)
    //    {

    //        DataRow dataRow = DesignationDataTable.NewRow();
    //        dataRow["TeacherDesignationKey"] = _sTeacherDesignationList[i].TeacherDesignationKey;
    //        dataRow["UserAccountKey"] = _sTeacherDesignationList[i].UserAccountKey;
    //        dataRow["JobDesignationCode"] = _sTeacherDesignationList[i].JobDesignationCode;
    //        dataRow["JobDescriptionDetail"] = _sTeacherDesignationList[i].JobDescriptionDetail;
    //        dataRow["StartDate"] = _sTeacherDesignationList[i].StartDate;
    //        dataRow["EndDate"] = _sTeacherDesignationList[i].EndDate;
    //        dataRow["Active"] = _sTeacherDesignationList[i].Active;
    //        dataRow["Remarks"] = _sTeacherDesignationList[i].Remarks;
    //        dataRow["Status"] = "Old";
    //        DesignationDataTable.Rows.Add(dataRow);
    //    }

    //    Session["TeacherDesignationsDT"] = DesignationDataTable;
    //}

    //private void CreateQualifyTable(TeacherQualtificationTableList _sTeacherQualifyList)
    //{
    //    // create DataTable object
    //    DataTable TeacherQualifyTable = new DataTable();
    //    Session["QualificationDT"] = TeacherQualifyTable;

    //    // auto increment column for productsDataTable
    //    DataColumn dataColumn = new DataColumn("TeacherQualtificationKey", System.Type.GetType("System.Int32"));
    //    dataColumn.AutoIncrement = true;
    //    dataColumn.AutoIncrementSeed = 1;
    //    dataColumn.AutoIncrementStep = 1;
    //    //dataColumn.Unique = true;
    //    TeacherQualifyTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("UserAccountKey", System.Type.GetType("System.Int32"));
    //    TeacherQualifyTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("QualificationName", System.Type.GetType("System.String"));
    //    TeacherQualifyTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("Organization", System.Type.GetType("System.String"));
    //    TeacherQualifyTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("Year", System.Type.GetType("System.String"));
    //    TeacherQualifyTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("GradeLevel", System.Type.GetType("System.String"));
    //    TeacherQualifyTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("Others", System.Type.GetType("System.String"));
    //    TeacherQualifyTable.Columns.Add(dataColumn);
    //    //Remarks

    //    dataColumn = new DataColumn("Status", System.Type.GetType("System.String"));
    //    TeacherQualifyTable.Columns.Add(dataColumn);
    //    //Remarks

    //    // After Creating columns you can add data rows to store the data dynamically

    //    for (int i = 0; i < _sTeacherQualifyList.Count; i++)
    //    {

    //        DataRow dataRow = TeacherQualifyTable.NewRow();
    //        dataRow["TeacherQualtificationKey"] = _sTeacherQualifyList[i].TeacherQualtificationKey;
    //        dataRow["UserAccountKey"] = _sTeacherQualifyList[i].UserAccountKey;
    //        dataRow["QualificationName"] = _sTeacherQualifyList[i].QualificationName;
    //        dataRow["Organization"] = _sTeacherQualifyList[i].Organization;
    //        dataRow["Year"] = _sTeacherQualifyList[i].Year;
    //        dataRow["GradeLevel"] = _sTeacherQualifyList[i].GradeLevel;
    //        dataRow["Others"] = _sTeacherQualifyList[i].Others;
    //        dataRow["Status"] = "Old";
    //        TeacherQualifyTable.Rows.Add(dataRow);
    //    }


    //    Session["QualificationDT"] = TeacherQualifyTable;
    //}

    //private void CreateSkillTable(TeacherOtherSkillsTableList _sTeacherSkillList)
    //{
    //    // create DataTable object
    //    DataTable TeacherSkillTable = new DataTable();

    //    // auto increment column for productsDataTable
    //    DataColumn dataColumn = new DataColumn("TeacherOtherSkillsKey", System.Type.GetType("System.Int32"));
    //    dataColumn.AutoIncrement = true;
    //    dataColumn.AutoIncrementSeed = 1;
    //    dataColumn.AutoIncrementStep = 1;
    //    //dataColumn.Unique = true;
    //    TeacherSkillTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("UserAccountKey", System.Type.GetType("System.Int32"));
    //    TeacherSkillTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("SkillName", System.Type.GetType("System.String"));
    //    TeacherSkillTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("Organization", System.Type.GetType("System.String"));
    //    TeacherSkillTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("NoOfYear", System.Type.GetType("System.String"));
    //    TeacherSkillTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("SkillLevel", System.Type.GetType("System.String"));
    //    TeacherSkillTable.Columns.Add(dataColumn);

    //    dataColumn = new DataColumn("Others", System.Type.GetType("System.String"));
    //    TeacherSkillTable.Columns.Add(dataColumn);
    //    //Remarks

    //    dataColumn = new DataColumn("Status", System.Type.GetType("System.String"));
    //    TeacherSkillTable.Columns.Add(dataColumn);
    //    //Remarks

    //    // After Creating columns you can add data rows to store the data dynamically

    //    for (int i = 0; i < _sTeacherSkillList.Count; i++)
    //    {

    //        DataRow dataRow = TeacherSkillTable.NewRow();
    //        dataRow["TeacherOtherSkillsKey"] = _sTeacherSkillList[i].TeacherOtherSkillsKey;
    //        dataRow["UserAccountKey"] = _sTeacherSkillList[i].UserAccountKey;
    //        dataRow["SkillName"] = _sTeacherSkillList[i].SkillName;
    //        dataRow["Organization"] = _sTeacherSkillList[i].Organization;
    //        dataRow["NoOfYear"] = _sTeacherSkillList[i].NoOfYear;
    //        dataRow["SkillLevel"] = _sTeacherSkillList[i].SkillLevel;
    //        dataRow["Others"] = _sTeacherSkillList[i].Others;
    //        dataRow["Status"] = "Old";
    //        TeacherSkillTable.Rows.Add(dataRow);
    //    }

    //    Session["TeacherOtherSkillsDT"] = TeacherSkillTable;
    //}

    //private void AddToDesignationTempTable(Int16 JobDesignationCode, string JobDescriptionDetail, string dStartDate, string dEndDate, string Remarks, bool Active)
    //{

    //    DataTable lDT = new DataTable();
    //    lDT = (DataTable)Session["TeacherDesignationsDT"];
    //    int count = lDT.Rows.Count;

    //    DataRow dataRow = lDT.NewRow();
    //    dataRow["TeacherDesignationKey"] = count + 1;
    //    dataRow["UserAccountKey"] = 0;
    //    dataRow["JobDesignationCode"] = JobDesignationCode;
    //    dataRow["JobDescriptionDetail"] = JobDescriptionDetail;
    //    string StartDate = dStartDate;
    //    var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
    //    DateTime objStartDate = Convert.ToDateTime(StartDate, dtfi1);
    //    dataRow["StartDate"] = objStartDate;
    //    string EndDate = dEndDate;
    //    var dtfi2 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
    //    DateTime objEndDate = Convert.ToDateTime(EndDate, dtfi2);
    //    dataRow["EndDate"] = objEndDate;
    //    dataRow["Active"] = Active;
    //    dataRow["Remarks"] = Remarks;
    //    dataRow["Status"] = "New";
    //    lDT.Rows.Add(dataRow);
    //    Session["TeacherDesignationsDT"] = lDT;
    //    lDT.AcceptChanges();
    //    gvDesignation.EditIndex = -1;
    //    gvDesignation.DataSource = lDT;
    //    gvDesignation.DataBind();
    //    ClearDesignationRecord();

    //}

    //private void AddToSalaryTempTable(Int16 PaymentTypeCode, Int16 CurrencyCode, string dStartDate, string dEndDate, string Amount, string Allotment1, string Allotment2, string Remarks, bool Active)
    //{

    //    DataTable lDT = new DataTable();
    //    lDT = (DataTable)Session["TeacherSalaryDT"];
    //    int count = lDT.Rows.Count;

    //    DataRow dataRow = lDT.NewRow();
    //    dataRow["TeacherSalaryKey"] = count + 1;
    //    dataRow["UserAccountKey"] = 0;
    //    dataRow["PaymentTypeCode"] = PaymentTypeCode;
    //    dataRow["CurrencyCode"] = CurrencyCode;
    //    string StartDate = dStartDate;
    //    var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
    //    DateTime objStartDate = Convert.ToDateTime(StartDate, dtfi1);
    //    dataRow["StartDate"] = objStartDate;
    //    string EndDate = dEndDate;
    //    var dtfi2 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
    //    DateTime objEndDate = Convert.ToDateTime(EndDate, dtfi2);
    //    dataRow["EndDate"] = objEndDate;
    //    dataRow["Amount"] = Amount.Equals(string.Empty) ? 0 : Convert.ToDouble(Amount);
    //    dataRow["Allotment1"] = Allotment1.Equals(string.Empty) ? 0 : Convert.ToDecimal(Allotment1);
    //    dataRow["Allotment2"] = Allotment2.Equals(string.Empty) ? 0 : Convert.ToDecimal(Allotment2);
    //    dataRow["Active"] = Active;
    //    dataRow["Remarks"] = Remarks;
    //    dataRow["Status"] = "New";
    //    lDT.Rows.Add(dataRow);
    //    Session["TeacherSalaryDT"] = lDT;
    //    lDT.AcceptChanges();
    //    gvSalary.EditIndex = -1;
    //    gvSalary.DataSource = lDT;
    //    gvSalary.DataBind();
    //    ClearSalaryRecord();

    //}

    //private void AddToQualifyTempTable(string QualificationName, string Organization, string Year, string GradeLevel, string Others)
    //{

    //    DataTable lDT = new DataTable();
    //    lDT = (DataTable)Session["QualificationDT"];
    //    int count = lDT.Rows.Count;

    //    DataRow dataRow = lDT.NewRow();
    //    dataRow["TeacherQualtificationKey"] = count + 1;
    //    dataRow["UserAccountKey"] = 0;
    //    dataRow["QualificationName"] = QualificationName;
    //    dataRow["Organization"] = Organization;
    //    dataRow["GradeLevel"] = GradeLevel;
    //    dataRow["Year"] = Year;
    //    dataRow["Others"] = Others;
    //    dataRow["Status"] = "New";
    //    lDT.Rows.Add(dataRow);
    //    Session["QualificationDT"] = lDT;
    //    lDT.AcceptChanges();
    //    dgvTeacherQualtification.EditIndex = -1;
    //    dgvTeacherQualtification.DataSource = lDT;
    //    dgvTeacherQualtification.DataBind();
    //    ClearQualificationRecord();

    //}

    //private void AddToSkillTempTable(string SkillName, string Organization, string NoOfYear, string SkillLevel, string Others)
    //{

    //    DataTable lDT = new DataTable();
    //    lDT = (DataTable)Session["TeacherOtherSkillsDT"];
    //    int count = lDT.Rows.Count;

    //    DataRow dataRow = lDT.NewRow();
    //    dataRow["TeacherOtherSkillsKey"] = count + 1;
    //    dataRow["UserAccountKey"] = 0;
    //    dataRow["SkillName"] = SkillName;
    //    dataRow["Organization"] = Organization;
    //    dataRow["SkillLevel"] = SkillLevel;
    //    dataRow["NoOfYear"] = NoOfYear;
    //    dataRow["Others"] = Others;
    //    dataRow["Status"] = "New";
    //    lDT.Rows.Add(dataRow);
    //    Session["TeacherOtherSkillsDT"] = lDT;
    //    lDT.AcceptChanges();
    //    gvTeacherOtherSkills.EditIndex = -1;
    //    gvTeacherOtherSkills.DataSource = lDT;
    //    gvTeacherOtherSkills.DataBind();
    //    ClearOtherSkillRecord();

    //}

    //private void UpdateDesignationTempTable(string TeacherDesignationKey, Int16 JobDesignationCode, string JobDescriptionDetail, string dStartDate, string dEndDate, string Remarks, bool Active)
    //{
    //    int _TeacherDesignationKey = Convert.ToInt32(TeacherDesignationKey);
    //    //int UserAccountKey = Convert.ToInt32(UserAccountKeyString);
    //    Int16 _JobDesignationCode = JobDesignationCode;
    //    string txtStartDate = dStartDate;
    //    var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
    //    DateTime objStartDate = Convert.ToDateTime(txtStartDate, dtfi1);
    //    string txtEndDate = dEndDate;
    //    var dtfi2 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
    //    DateTime objEndDate = Convert.ToDateTime(txtEndDate, dtfi1);
    //    DataTable lDT = new DataTable();
    //    lDT = (DataTable)Session["TeacherDesignationsDT"];
    //    foreach (DataRow lDR in lDT.Rows)
    //    {
    //        if (_TeacherDesignationKey == Convert.ToInt32(lDR["TeacherDesignationKey"]))
    //        {
    //            lDR["JobDesignationCode"] = _JobDesignationCode;
    //            lDR["JobDescriptionDetail"] = JobDescriptionDetail;
    //            lDR["StartDate"] = objStartDate;
    //            lDR["EndDate"] = objEndDate;
    //            lDR["Active"] = Active;
    //            lDR["Remarks"] = Remarks;
    //            lDR["Status"] = "Edit";

    //        }
    //    }
    //    lDT.AcceptChanges();
    //    gvDesignation.EditIndex = -1;
    //    gvDesignation.DataSource = lDT;
    //    gvDesignation.DataBind();
    //    ClearDesignationRecord();
    //    btnDesignationAdd.Text = "Add New";
    //}

    //private void UpdateSalaryTempTable(string TeacherSalaryKey, Int16 PaymentTypeCode, Int16 CurrencyCode, string Amount, string Allotment1, string Allotment2, string dStartDate, string dEndDate, string Remarks, bool Active)
    //{
    //    int _TeacherSalaryKey = Convert.ToInt32(TeacherSalaryKey);
    //    //int UserAccountKey = Convert.ToInt32(UserAccountKeyString);        
    //    string txtStartDate = dStartDate;
    //    var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
    //    DateTime objStartDate = Convert.ToDateTime(txtStartDate, dtfi1);
    //    string txtEndDate = dEndDate;
    //    var dtfi2 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
    //    DateTime objEndDate = Convert.ToDateTime(txtEndDate, dtfi1);
    //    DataTable lDT = new DataTable();
    //    lDT = (DataTable)Session["TeacherSalaryDT"];
    //    foreach (DataRow lDR in lDT.Rows)
    //    {
    //        if (_TeacherSalaryKey == Convert.ToInt32(lDR["TeacherSalaryKey"]))
    //        {
    //            lDR["PaymentTypeCode"] = PaymentTypeCode;
    //            lDR["CurrencyCode"] = CurrencyCode;
    //            lDR["Amount"] = Amount.Equals(string.Empty) ? 0 : Convert.ToDouble(Amount);
    //            lDR["Allotment1"] = Allotment1.Equals(string.Empty) ? 0 : Convert.ToDecimal(Allotment1);
    //            lDR["Allotment2"] = Allotment2.Equals(string.Empty) ? 0 : Convert.ToDecimal(Allotment2);
    //            lDR["StartDate"] = objStartDate;
    //            lDR["EndDate"] = objEndDate;
    //            lDR["Active"] = Active;
    //            lDR["Remarks"] = Remarks;
    //            lDR["Status"] = "Edit";

    //        }
    //    }
    //    lDT.AcceptChanges();
    //    gvSalary.EditIndex = -1;
    //    gvSalary.DataSource = lDT;
    //    gvSalary.DataBind();
    //    ClearSalaryRecord();
    //    btnSalaryAdd.Text = "Add New";
    //}

    //private void UpdateQualificationTempTable(string TeacherQualtificationKey, string QualificationName, string Organization, string Year, string GradeLevel, string Others)
    //{
    //    int _TeacherQualtificationKey = Convert.ToInt32(TeacherQualtificationKey);

    //    DataTable lDT = new DataTable();
    //    lDT = (DataTable)Session["QualificationDT"];
    //    foreach (DataRow lDR in lDT.Rows)
    //    {
    //        if (_TeacherQualtificationKey == Convert.ToInt32(lDR["TeacherQualtificationKey"]))
    //        {
    //            lDR["Year"] = Year;
    //            lDR["GradeLevel"] = GradeLevel;
    //            lDR["QualificationName"] = QualificationName;
    //            lDR["Organization"] = Organization;
    //            lDR["Others"] = Others;
    //            lDR["Status"] = "Edit";

    //        }
    //    }
    //    lDT.AcceptChanges();
    //    dgvTeacherQualtification.EditIndex = -1;
    //    dgvTeacherQualtification.DataSource = lDT;
    //    dgvTeacherQualtification.DataBind();
    //    ClearQualificationRecord();
    //    btnQualifyAdd.Text = "Add New";
    //}

    //private void UpdateSkillTempTable(string TeacherOtherSkillsKey, string SkillName, string Organization, string NoOfYear, string SkillLevel, string Others)
    //{
    //    int _TeacherOtherSkillsKey = Convert.ToInt32(TeacherOtherSkillsKey);

    //    DataTable lDT = new DataTable();
    //    lDT = (DataTable)Session["TeacherOtherSkillsDT"];
    //    foreach (DataRow lDR in lDT.Rows)
    //    {
    //        if (_TeacherOtherSkillsKey == Convert.ToInt32(lDR["TeacherOtherSkillsKey"]))
    //        {
    //            lDR["NoOfYear"] = NoOfYear;
    //            lDR["SkillLevel"] = SkillLevel;
    //            lDR["SkillName"] = SkillName;
    //            lDR["Organization"] = Organization;
    //            lDR["Others"] = Others;
    //            lDR["Status"] = "Edit";

    //        }
    //    }
    //    lDT.AcceptChanges();
    //    gvTeacherOtherSkills.EditIndex = -1;
    //    gvTeacherOtherSkills.DataSource = lDT;
    //    gvTeacherOtherSkills.DataBind();
    //    ClearOtherSkillRecord();
    //    btnSkillAdd.Text = "Add New";
    //}
    #endregion



}